Sometimes I use this code when I want to run WordPress externally.
update.php
function find_wordpress_base_path() {
$dir = dirname(__FILE__);
do {
//it is possible to check for other files here
if( file_exists($dir."/wp-config.php") ) {
return $dir;
}
} while( $dir = realpath("$dir/..") );
return null;
}
define( 'BASE_PATH', find_wordpress_base_path()."https://wordpress.stackexchange.com/" );
define('WP_USE_THEMES', false);
global $wp, $wp_query, $wp_the_query, $wp_rewrite, $wp_did_header;
require(BASE_PATH . 'wp-load.php');
$post_id = $_POST['id'];
$title = $_POST['title'];
// Update post
$my_post = array(
'ID' => $post_id,
'post_title' => $title, // new title
);
// Update the post into the database
wp_update_post( $my_post );
Related Posts:
- Build A Custom SQL Query for WordPress Search
- My Custom Post Type AJAX Query is Returning no posts – why?
- WordPress Custom Form – Getting Query Vars, Weird Glitch?
- Post form – AJAX won’t upload featured image – Plugin development
- How to Send Pingbacks for all Posts in WordPress?
- How to display 8 posts in four columns and 2 rows on a carousel slide?
- Display articles with a different template in the home page | Solved |
- How can I check if a post with a particular slug or title exists?
- WordPress sorting posts by date and title using a dropdown
- How to get post image caption by index
- posts_per_page displays only 2 posts instead of 4 posts
- Inside Array – “unidentified index” error with “prepare was called incorrectly” despite not calling the prepared statement with wordpress [closed]
- Is there anyway I can call the year once?
- Query on a repeater date (acf)
- Time Stamp In A WordPress Post Title That Does Not Keep Refreshing
- How to get post titles by post ID and integrate with my code?
- Check $post->ID against multiple values
- wp_update_post gives 500 internal error
- Trying to get post ID outside loop on blog page
- Don’t update modified post date when user add a product review or comment?
- Limit the number of characters/words in an excerpt for a related posts section
- Posts missing on author page
- How to allow users to save list of posts in wordpress?
- Infinite looping next post link within a certain category on a post
- Trying to show the category of a post in the post display
- Split post or page content in two or more columns
- Enqueue script only on child pages of custom post types
- Attach and retrive multiple pdf files to post or page
- WordPress recent post
- Need to show 7 posts from actual date
- Check the database for a postmeta field
- Show a text if the post has written by author user role in WordPress
- Can I disable auto increment of WordPress Posts Database to utilize previously deleted records?
- Send POST request to Flask app from functions.php file
- Getting info about selected posts using one WP_Query
- Closing Comments conditionally in comments.php
- Change upload URL by mime type
- How to center all text body in single.php at once?
- Get list of posts from attachment
- How to pull date/time in french format for wordpress post?
- Send Notification after post published was working but stopped after the last WP update
- How to use a PHP file to control the content of a blog post
- Having trouble with customizing blog posts on the home page
- Related Posts: if there is no category use tags
- My blog posts section seems to be rendering the other blog posts inside the first? :/
- WordPress post insertion from PHP file
- LinkedIn Share Post Button
- How to display last whole post on the homepage
- How do if all posts has this category ID then do this
- How to insert text into post based on category – via single.php file
- When working with a post, almost all wp_postmeta are deleted
- Make sticky post with FacetWP
- WordPress Single Post Pagination Numbered and Navigational
- Getting page / post URL on publish and / or update
- Let user select the number of posts shown per page jquery error
- Get the total Author Favorited posts
- Add wp posts to cutom masonry grid
- Displaying POST content with HTML tags and all
- Generate random access token to a post page
- Get current_post in reverse order with pagination
- Getting error in sql query
- Displaying 3 Category Posts differently
- Pagination in WP Queries
- How do I generate formatted permalinks as specified in backend options?
- Using Tag Groups: Displaying groups and adjacent tags of current post
- Setting at job with shortcode not working
- How do I get the featured post to share on Social Media and show on Individual Post pages?
- Add div after every 4 posts then every 2 posts for a responsive loop
- Only display notification on single post
- Insert div after every three posts in home.php [duplicate]
- PHP tag in post content makes wordpress go crazy
- Unable to get Post Category Name and URL
- $post->ID calls for current page, but what is the code to call for any new page created and published in WordPress?
- Blog Posts not sorted and pagination not adjusted after filtering some category
- Set post to draft if matching word is found in the post
- Disable single posts, but keep archive
- Add multiple HTML attributes to an Elementor button
- WooCommerce: write featured image dimensions to custom fields in product’
- How to create a WordPress PAGE in another folder?
- How do I get a function to work in single.php
- transition_post_status hook, works – but not if the post is new
- How to use a conditional statement in a post loop but not count towards the “posts_per_page” if false
- Count the number of matching post names in foreach loop
- Need Help With Making Full-Width Template for Blog Posts (common methods aren’t working)
- Bulk data save in custom table
- How to change post date and post time in WordPress automatically with a function
- How to get ACF field to show up on all posts on front end?
- Global update of records after import WP All Import Pro
- Display posts based on the selected category when no subcategory is chosen
- Insert attributes names according to language with polylang programmatically
- Display two previous posts on single.php
- (plesk)After adding 1000 youtube url to my 1000 different wordpress article, my all websites doesnt show yt url as embed
- change the blog in the url if you go from a specific page wordpress
- How to make posts_like_dislike reference current post when iterating?
- Trying to add a wp block and update the post content using PHP (wp_post_update)
- Updating post_parent caused the website to become unresponsive for 40 seconds or more
- Category Attachment Pagination 404 Error on 2nd Page
- Warning: Undefined variable $post_id
- Issues applying JSON body filters in EU F&T Portal SEARCH API with WordPress integration
- How to display only the first 2 words of a post title