I have an external script I wrote (for admins only) that loads in the following at the top:


I'm aware that it can be a plugin, but it's just not right now.. it's just a standard php script.

Inside this script I have a form where it allows the person viewing to update a title.

Here is my code when they submit the form:

$post_data = array(
  'ID'         => $_POST['post_id'],
  'post_title' => $_POST['post_title']

wp_update_post() actually returns an ID, which makes me think its working, but the post simply doesn't change, and the title never updates.

What might I be missing here? At the very least I would expect an error if it doesn't work.

I'm positive the ID and the Title are correct/filled in.

  • Are you updating revision IDs, perhaps?
    – s_ha_dum
    Commented Apr 30, 2014 at 16:52
  • I'm finding the ID by using $post->ID. Would that always return the actual post, or could that return revision IDs?
    – Tallboy
    Commented Apr 30, 2014 at 17:00
  • Your code is very out of context. I can't say what is happening really.
    – s_ha_dum
    Commented Apr 30, 2014 at 17:05

1 Answer 1


Sometimes I use this code when I want to run WordPress externally.


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()."/" );
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 );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.