1

i make php file outside from wordpress folder to edit wordpress post and i get error when i use this code.

wp_update_post

<?php include '/go1/wp-includes/post.php';?>

<?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 );
?>

my error is:

Notice: Use of undefined constant ARRAY_A - assumed 'ARRAY_A' in D:\AAApc\training\XAMPP\htdocs\go1\wp-includes\post.php on line 3628

Fatal error: Call to undefined function wp_cache_get() in D:\AAApc\training\XAMPP\htdocs\go1\wp-includes\post.php on line 664

2

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().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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