Updating post_parent by id (many times)

Question

How can I update post_parent by ids?

I tried:

add_action('init','updating_parent');

function updating_parent(){

    $args = array(
       'post__in' => array(208,51) 
    );

    $my_posts = get_posts( $args );

    foreach ( $my_posts as $my_post ):

        $my_post['post_parent'] = 12;

        wp_update_post( $my_post );

    endforeach;
}

But this is not working. But even it wouldn’t be what I need. Since I have data like:

ID => post_parent
208 => 12
51 => 19
and so on...

So I need an array at post_parent as well.

0
Emanuel Schiendorfer 6 years 2017-02-02T17:50:31-05:00 0 Answers 58 views 0

Leave an answer

Browse
Browse