1

I recently imported large number of custom posts into wordpress. all works fine, except one taxonomy which is imported, but not show at the front end, until i click on every post "update" button. I have 810 posts and this is not a solution...

i think it should be the way to run MYSQL command to force all post update without making any changes. Please help me with command, i searched for plugins and cannot find anything suitable

Thank you

  • Small hint, the UI have also a bulk action to update all posts. You should change the list of all posts, right top screen options for the count of posts. After this use the bulk action to update all posts, there are listed. – bueltge Feb 20 '18 at 9:05
  • Sorry, i am not a programmer... if you mean bulk action on admin screen, it doesn't work. the only think works for me is going to every post and pressing "update" button – AlexPTY Feb 20 '18 at 9:14
  • Yes, it is for users, without coding know how. See on the wp-admin/edit.php and select the edit option int the bulk options, select also all posts and click Apply. Now the first selected post open the quick edit view and you can change data, that well update in all selected post after update. – bueltge Feb 20 '18 at 9:35
  • as i said, it doesn't work from the bulk action, only every post "update" button works – AlexPTY Feb 20 '18 at 9:50
5

There are 2 ways that you could do this. The first and more difficult is to write a program, the other is to do a bulk update. Why do difficult when easy way will work equally well? and especially as this is a once-off requirement

The easy way:

  1. In the admin dashboard, select the view with all posts for your custom type
  2. Select all the posts (tick them) - You can see more posts by clicking 'Screen Options' at the top right of the view and increasing the number of items per page
  3. Click the down arrow next to 'Bulk Actions' and select edit
  4. Press 'Apply' - you will get a screen with a selection of changes you can make
  5. Make some change, like add a tag or change author (whatever)
  6. Press 'Update'

That should do it.

The 'difficult' way:

In case anyone wants to use the code solution, you can add the code below to the functions.php file in your child theme.

function my_update_posts() {
    //$myposts = get_posts('showposts=-1');//Retrieve the posts you are targeting
    $args = array(
        'post_type' => 'post',
        'numberposts' => -1
    );
    $myposts = get_posts($args);
    foreach ($myposts as $mypost){
        $mypost->post_title = $mypost->post_title.'';
        wp_update_post( $mypost );
    }
}
add_action( 'wp_loaded', 'my_update_posts' );

Remember to run this only once and then remove it or comment out the add_action line otherwise it will run every time a new page is loaded.

I included this option in case anyone wants a start template for updating all post titles or some other property in all posts.

| improve this answer | |
  • 1
    Or use -1 for all posts instead of the 1000 in this example. – bueltge Feb 20 '18 at 11:20
  • Easy way doesn't work. Quick Edit doesn't work as i said earlier, only full edit of the post works. I do not know why, maybe because this button trigger "publish" command instead of the "update". Is there a way to to force the "publish" the posts instead of "update"? – AlexPTY Feb 20 '18 at 11:38
  • 1
    nop, doesn't work. i think i will manually edit all posts tomorrow, it will take couple of hours, but i already spent half of the day looking for solutions. Thank you everyone – AlexPTY Feb 20 '18 at 12:44
  • Same as @AlexPTY this code must be similar to the bulk update. Has no effect. – Michael Rogers Mar 27 at 19:51
1

First: Get all posts using get_posts or WP_Query.

$query_posts = new WP_Query( array(
    'nopaging' => true,
) );

Second: Do loop for posts and use wp_update_post() for each post and set ID parameter.

while ( $query_posts->have_posts() ) :
    $query_posts->the_post();
    wp_update_post( array(
        'ID' => get_the_ID(),
        'post_content' => get_the_content(),
    ) );
endwhile;

Place this code to init action or header/footer. Update page once and remove code. Place this code in functions.php and all your posts will be updated on page reload.

add_action( 'init', function () {
    $query_posts = new WP_Query( array(
        'nopaging' => true,
    ) );

    while ( $query_posts->have_posts() ) :
        $query_posts->the_post();
        wp_update_post( $post );
    endwhile;
    wp_reset_postdata();
} );
| improve this answer | |
  • Thank you Maxim, but this code deleted content of all my posts on refresh. i will restore everything and try other solution – AlexPTY Feb 20 '18 at 11:31
  • set content from your current post to post_content in wp_update_post() function. wp_update_post( array( 'ID' => get_the_ID(), 'post_content' => get_the_content() ) ); – Maxim Sarandi Feb 20 '18 at 11:33
  • sorry, i am not a programmer. i can only copy/paste ;) – AlexPTY Feb 20 '18 at 11:48
  • Edited my post. – Maxim Sarandi Feb 20 '18 at 11:50
  • sorry, it just erases the content of the post on refresh. – AlexPTY Feb 20 '18 at 11:56
0

For any future interested people: to bulk update posts one by one, you can use chrome extension web scrapper that will automatize clics on update button on every post.

| improve this answer | |

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.