Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update all wordpress posts

Tags:

wordpress

I need make all of my posts update. I use bulk upload for store, but in web page posts/products dont show, when i hit update, posts/products are showed up.

I think use wordpress default update function:

// Update post 37
  $my_post = array();
  $my_post['ID'] = 37;
  $my_post['post_content'] = 'This is the updated content.';

  // Update the post into the database
  wp_update_post( $my_post );

But how to get in arrays all posts id?

like image 849
Foxsk8 Avatar asked Dec 12 '22 08:12

Foxsk8


2 Answers

Here you go, you just loop through the posts with a foreach.

/*
Plugin Name: Example
Description: This is not just a plugin, it's <em>CODE</em>..
Author: 
*/
add_action('init','example_hide');

function example_hide(){

    $my_posts = get_posts( array('post_type' => 'post', 'numberposts' => 10 ) );

    foreach ( $my_posts as $my_post ):

    $my_post['post_content'] = 'This is the updated content.';

    wp_update_post( $my_post );

    endforeach;
}
like image 168
DigitalDesignDj Avatar answered Feb 04 '23 14:02

DigitalDesignDj


You should be able to use WordPress' get_posts function. Try:

$all_posts = get_posts('numberposts=');
like image 20
Martey Avatar answered Feb 04 '23 12:02

Martey