Support » Plugin: Pods - Custom Content Types and Fields » wp_update_post not working

  • Resolved edash22

    (@edash22)


    I have a relatively simple custom post that I created with Pods (which I think is terrific). I am trying to programmatically update a post, which is something I’ve not done before. I’ve looked at quite a few examples, and it seems straightforward, but my code is not working. It is making the call to wp_update_post. I am also not getting any errors. I’m wondering if there is a setting or something else that is preventing the post from updating. Here’s the code I have:

    $donor = new WP_Query( $args ); 
    $found = $donor->post_count;
    if ( $found >= 1 ) {
        $weight = 188;
        $age = 22;
    
        while ( $donor->have_posts() ) {
            $donor->the_post();
            $update_post = array(
                'ID'     => get_the_id(),
                'weight' => $weight,
                'age'    => $age,
            );
            $ustatus = wp_update_post( $update_post, true );
            if (is_wp_error($ustatus)) {
                echo 'Error '. $ustatus->get_error_code() .': '. $ustatus->get_error_message();
            }
        }
    }

    Thank you for any help!

    • This topic was modified 3 months, 2 weeks ago by edash22.
Viewing 1 replies (of 1 total)
  • Thread Starter edash22

    (@edash22)

    I’ll answer my own question … the fields need to go into a meta_input item.
    So, it would look more like this:

    $update_post = array(
                'ID'     => get_the_id(),
                'meta_input' => array(
                            'weight' => $weight,
                            'age' => $age
                           )
            );

    This is working for me, so I’ll consider it closed.

    • This reply was modified 3 months, 2 weeks ago by edash22.
Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.