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:
- Disable Attachment Pages Completely
- Inject post (from specific category) between posts in Loop
- Remove option to allow trackbacks/pingbacks from post page options
- How to get year, month and hour in WordPress?
- Handling an Ajax form submit
- New Plugin Review
- Print number of post (in reverse)
- Use template for posts with a particular category grandparent
- Count number of published posts by type
- Automatically generate Post/Page from searched Database item?
- Get taxonomy terms only of the WP_Query current posts
- How to get 2 or multiple custom post types in wordpress functions.php
- “before delete post” action fire when the post is updated?
- Displaying a button on each post
- Hide post if matches current month and year
- Creating bulk posts with Youtube videos
- Automatically add custom CSS to new posts using a category template
- How Display Posts on category
- Query all posts of a custom taxonomy term
- Getting a specific post values to another div or modal
- Displaying the last post on static homepage
- Unreadable pagination
- how do I get a specific post from a post with a subcategory in WP
- Automatically create child pages and grandchild pages when saving a (parent) page
- Open post-content in archive page in a Modal box with bootstrap
- remove post that has no content
- Custom posts in different columns style
- How to show only subcategories in parent category not parent category?
- 404 error when I acess the second page of post-type
- WP Insert Post and then go to post
- Copy taxonomy terms from one post to another programmatically
- Get latest post from all categories except one
- What file have I to create in my custom WordPress theme to show all the post belonging to a specific category?
- Parse error: syntax error, unexpected end of file
- Load Posts on Click via Ajax into a DIV
- How to catch wordpress post ID when it’s published
- Find Site ID From WP_Post
- Reading settings in the home page precisely home.php
- WordPress upload file size error even after raising php limits
- create front-end users post list by specific category
- Displaying list of posts in category page
- How can I get “Previous” and “Next” to show in the navigation besides the links?
- Error display post thumbnails for previous and next post
- how to edit a specific post slug using a php code?
- form $_post action value gets truncated after it passes through two forms
- How to pick “full/thumbnail” images in the loop?
- Saving a post ID to use in a form elsewhere on website
- Prevent post from being published and show error
- Wp Query : Order by distance lat,lon
- remove specificly the last tag in all posts
- Pagination at category doesnt work with same name of page
- Add posts to custom table in database instead of wp_posts
- get value from get_post_meta then reuse it in another get_post_meta
- How to show categories and date on posts
- WordPress Post Block Element not properly parsed with the_content filter
- Build A Custom SQL Query for WordPress Search
- WordPress Custom Form – Getting Query Vars, Weird Glitch?
- How to Send Pingbacks for all Posts in WordPress?
- 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
- Query on a repeater date (acf)
- Trying to get post ID outside loop on blog page
- 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
- Check the database for a postmeta field
- Send POST request to Flask app from functions.php file
- 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 display last whole post on the homepage
- How to insert text into post based on category – via single.php file
- When working with a post, almost all wp_postmeta are deleted
- Add wp posts to cutom masonry grid
- Displaying POST content with HTML tags and all
- Generate random access token to a post page
- Pagination in WP Queries
- Add div after every 4 posts then every 2 posts for a responsive loop
- Only display notification on single post
- Get posts associated with media attachment
- ‘posts_per_page’ in costum page type
- Can’t put a hyperlink on Featured Post’s Image
- Passed variable gets undefined variable error on insert on next page
- WordPress get_post_meta issue
- List of child pages fetch next results at link click
- Automatically create a loop for post ID
- Why does WP_Query show only the same post even with different categories and endwhile?
- Display pages from specific page template
- Query posts by custom fields (object post)
- How to modify this function to exclude also the post belonging to a specific category?
- How to display the date under the post title?
- Excerpt all post content Content Same Size without word cutting off
- Set post to draft if matching word is found in the post
- Add multiple HTML attributes to an Elementor button
- How to create a WordPress PAGE in another folder?
- How do I get a function to work in single.php
- 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)