The key to using WordPress outside of WordPress is include the wp-load.php file:
So your code will like:
<?php
// Include the wp-load'
include('YOUR_WP_PATH/wp-load.php');
// Update post 1 hello word
$my_post = array(
'ID' => 1,
'post_title' => 'This is the updated post title.',
'post_content' => 'This is the updated content.',
);
// Update the post into the database
wp_update_post( $my_post );
?>
It’s should work…
Once the wp-load.php file is included, the entire wealth of WordPress functions is provided to you. While the sample code above gets recent posts, you can do your own custom queries with WP_Query or get_posts().
Related Posts:
- Sorting list of sites from multisite network using wp_get_sites
- How to store the_title() into a variable to reutrn the value, not just echo it
- Metabox repeating fields – radio buttons not saving correctly
- How can merge two arrays values in one array and save in database
- How to update single value in multi dimensional Post Meta?
- Compare two meta key values against each other inside the get_posts array?
- Looping through WP_Post Object
- Need to get specific data from array
- Using a javascript file to access a get posts array
- Create an array from an array
- WP_User_Query order by meta_key that is an array
- Generate an array of parent/child page IDs, based on parent page name
- How do I output a database option that is an array into a get_posts array?
- Can an array be used as a meta_query value?
- Listing and displaying WooCommerce Shipping Zones in the frontend? [closed]
- How do I dynamically generate args for wp_query?
- List of posts by day of the week
- Check if term object is in array
- Must Use Plugin Causing Query Error
- ‘orderby’ => ‘rand’ alternative for better performance?
- How to convert objects into arrays
- Parsing php string in jquery [closed]
- Admin Options page. Save as Array
- PHP get the first post separately from array returned by wpdb->get_results()
- Working with query_posts ( arrays and query strings)
- how can i show only the parents in owl-carousel?
- Create shortcodes within foreach loop (using array)
- Using a variable in is_page(array())
- Remove duplicates – array_unique()
- How can I add multiple ‘tax_query’ arrays via a loop?
- How to properly loop through these external URLs to get them into the sitemap using this hook
- Recent posts with featured image or fallback image with permalink
- Call global variable array() in woocommerce child/template
- Storing Array from returned database query and using the array in a new query
- get_the_tags() not iterating through for/while loop, but will with foreach
- get a simple array of all of the term names that exist in all taxonomies
- Populate dropdown with Child Pages based on Parent Page chosen
- How to use $query->set with post__in?
- Reprinting tags with all attributes
- PHP Array Returning [object Object]. Tried existing answers results with no luck
- foreach loop still echoes array
- Exclude posts based on meta value
- Checking array against author id in loop
- Alter required message using comment form api
- Advanced Custom Fields – display label and value only if value entered
- meaning of (array)function()
- Grouping posts by a custom meta value
- wp_force_remove_style’ not found
- How to fix this warning:call_user_func_array() expects exactly 2 parameters, 1 given in D:\wamp\www\…….\wp-includes\class-wp-hook.php on line 286
- How can I access string value in an array?
- How to use if statement in an array? [closed]
- How to array only one key from another array
- Filtering a function’ output for a new continued function
- Get html data with javascript to php array and store to wordpress database
- Update post title from external file?
- How do I create a numbered list with PHP? [closed]
- Why is an array created in a function hooked to customize register populated when customizer is loaded but not when the front-end is loaded?
- How to use array in function to get only value I want
- Error while setting role
- Get categories names as an array to use it in theme settings
- How to get the last category name of a child category?
- How to say if meta_value is greater than 0 in an array?
- How to use two meta_compare in an array?
- Warning: in_array() null given in PHP function
- Foreach loop inside an array_merge
- Loop over Array and get the distinct ids
- How to access or parse key/values that have “string”
- If Array Values Match Another Array’s Values, Then
- Remove empty terms from array, sort alphabetically, update back to repeating field
- WordPress loop by meta key that is an array? and how loop multiple arrays
- Only show first image in foreach loop
- Conditional multidimensional arrays and array_map
- How to set if meta_value is lower < than other meta_value in a get_posts array?
- How to print array of specific item
- What is this mark for “? function()” [closed]
- How to combine array info [closed]
- Populate checkboxes from array
- Use php array outside his function
- PHP Use Declared array Variable inside already Declared Array
- Retrieve Array from within Array [closed]
- Force array to be a string [closed]
- Why is my array_diff usage breaking things?
- get_body_params() is always empty in POST request
- Grabbing value of input field inside of array
- save array of objects with update_option
- Custom WordPress Function – Adding items from Foreach Loop into an array and Updating Field based on array of IDs (ACF + WooCommerce)
- How to initialise WP_Query on the basis of a specific meta_value and continue iterating rest?
- How to group by column a and sum column b and c in a php array
- Replace block content with an array
- Adding date and time to the same request
- PHP how to submit array elements to database
- PHP – Converting elements to actual values
- Send emails to individual subscribers when CPT post is deleted (trashed)
- How to pass php array to external js file in WordPress
- Insert attributes names according to language with polylang programmatically
- Trying to add a wp block and update the post content using PHP (wp_post_update)
- Get check box values inside array for use in posting form data
- Warning: Array to string conversion in /css/base.php on line 500 [closed]
- Updating from multiple array custom table
- Inserting more than one array into same row