Skip to main content
added 9 characters in body
Source Link

I have a post and i need to update its post_parent. So i have used followingbelow code to update the post_parent value. Old post_parent is 844 and using query i have updated the value to 370 using below:

    global $wpdb;
    $table_name = $wpdb->prefix . "posts";
    $add_plan_to_team = $wpdb->update( $table_name, array( 'post_parent' => '370' ), array('ID'=> '84887'));
    // UPDATE wp_posts SET post_parent=370 WHERE ID=84887 

OnIn next screenline , i need to get the post above post and then perform some functions. I am doing it like this

     $post = get_post( 84887 );

But instead of returning updated values, i am getting the old post_parent value in return. Like below

WP_Post Object
(
    [ID] => 84887
    [post_author] => 2
    [post_date] => 2020-02-27 10:55:11
    [post_date_gmt] => 2020-02-27 10:55:11
    [post_content] => 
    [post_title] => MyTeam
    [post_excerpt] => 
    [post_status] => publish
    [comment_status] => closed
    [ping_status] => closed
    [post_password] => 
    [post_name] => allus-cu
    [to_ping] => 
    [pinged] => 
    [post_modified] => 2020-08-24 19:03:02
    [post_modified_gmt] => 2020-08-24 19:03:02
    [post_content_filtered] => 
    [post_parent] => 844   // This value is not correct. This should be 370
    [guid] => https://train.localdev.com/?post_type=wc_memberships_team&p=84887
    [menu_order] => 0
    [post_type] => wc_memberships_team
    [post_mime_type] => 
    [comment_count] => 0
    [filter] => db
)

I have checked in Database and in database, post_parent value is updated one.

Complete Code in all together:

global $wpdb;
$table_name = $wpdb->prefix . "posts";
$add_plan_to_team = $wpdb->update( $table_name, array( 'post_parent' => '370' ), array('ID'=> '84887'));

if($add_plan_to_team){
    $post = get_post( $team_id, 'OBJECT', 'db' );
    echo '<h1> team_updated </h1>';
    print_r($post);            
}

Please tell me how can i fix it.

I have a post and i need to update its post_parent. So i have used following to update the post_parent value. Old post_parent is 844 and using query i have updated the value to 370 using below:

    global $wpdb;
    $table_name = $wpdb->prefix . "posts";
    $add_plan_to_team = $wpdb->update( $table_name, array( 'post_parent' => '370' ), array('ID'=> '84887'));
    // UPDATE wp_posts SET post_parent=370 WHERE ID=84887 

On next screen, i need to get the post above post and then perform some functions. I am doing it like this

     $post = get_post( 84887 );

But instead of returning updated values, i am getting the old post_parent value in return. Like below

WP_Post Object
(
    [ID] => 84887
    [post_author] => 2
    [post_date] => 2020-02-27 10:55:11
    [post_date_gmt] => 2020-02-27 10:55:11
    [post_content] => 
    [post_title] => MyTeam
    [post_excerpt] => 
    [post_status] => publish
    [comment_status] => closed
    [ping_status] => closed
    [post_password] => 
    [post_name] => allus-cu
    [to_ping] => 
    [pinged] => 
    [post_modified] => 2020-08-24 19:03:02
    [post_modified_gmt] => 2020-08-24 19:03:02
    [post_content_filtered] => 
    [post_parent] => 844   // This value is not correct
    [guid] => https://train.localdev.com/?post_type=wc_memberships_team&p=84887
    [menu_order] => 0
    [post_type] => wc_memberships_team
    [post_mime_type] => 
    [comment_count] => 0
    [filter] => db
)

I have checked in Database and in database, post_parent value is updated one.

Complete Code in all together:

global $wpdb;
$table_name = $wpdb->prefix . "posts";
$add_plan_to_team = $wpdb->update( $table_name, array( 'post_parent' => '370' ), array('ID'=> '84887'));

if($add_plan_to_team){
    $post = get_post( $team_id, 'OBJECT', 'db' );
    echo '<h1> team_updated </h1>';
    print_r($post);            
}

Please tell me how can i fix it.

I have a post and i need to update its post_parent. So i have used below code to update the post_parent value. Old post_parent is 844 and using query i have updated the value to 370 using below:

    global $wpdb;
    $table_name = $wpdb->prefix . "posts";
    $add_plan_to_team = $wpdb->update( $table_name, array( 'post_parent' => '370' ), array('ID'=> '84887'));
    // UPDATE wp_posts SET post_parent=370 WHERE ID=84887 

In next line , i need to get the post and then perform some functions. I am doing it like this

     $post = get_post( 84887 );

But instead of returning updated values, i am getting the old post_parent value in return. Like below

WP_Post Object
(
    [ID] => 84887
    [post_author] => 2
    [post_date] => 2020-02-27 10:55:11
    [post_date_gmt] => 2020-02-27 10:55:11
    [post_content] => 
    [post_title] => MyTeam
    [post_excerpt] => 
    [post_status] => publish
    [comment_status] => closed
    [ping_status] => closed
    [post_password] => 
    [post_name] => allus-cu
    [to_ping] => 
    [pinged] => 
    [post_modified] => 2020-08-24 19:03:02
    [post_modified_gmt] => 2020-08-24 19:03:02
    [post_content_filtered] => 
    [post_parent] => 844   // This value is not correct. This should be 370
    [guid] => https://train.localdev.com/?post_type=wc_memberships_team&p=84887
    [menu_order] => 0
    [post_type] => wc_memberships_team
    [post_mime_type] => 
    [comment_count] => 0
    [filter] => db
)

I have checked in Database and in database, post_parent value is updated one.

Complete Code in all together:

global $wpdb;
$table_name = $wpdb->prefix . "posts";
$add_plan_to_team = $wpdb->update( $table_name, array( 'post_parent' => '370' ), array('ID'=> '84887'));

if($add_plan_to_team){
    $post = get_post( $team_id, 'OBJECT', 'db' );
    echo '<h1> team_updated </h1>';
    print_r($post);            
}

Please tell me how can i fix it.

No evidence in the question this is Multisite-related
Link
Pat J
  • 12.3k
  • 2
  • 28
  • 36
added 11 characters in body
Source Link

I have a post and i need to update its post_parent. So i have used following to update the postpost_parent value. Old Post IDpost_parent is 844 and using query i have updated the value to 370 using below:

    global $wpdb;
    $table_name = $wpdb->prefix . "posts";
    $add_plan_to_team = $wpdb->update( $table_name, array( 'post_parent' => '370' ), array('ID'=> '84887'));
    // UPDATE wp_posts SET post_parent=370 WHERE ID=84887 

On next screen, i need to get the post above post and then perform some functions. I am doing it like this

     $post = get_post( 84887 );

But instead of returning updated values, i am getting the old post_parent value in return. Like below

WP_Post Object
(
    [ID] => 84887
    [post_author] => 2
    [post_date] => 2020-02-27 10:55:11
    [post_date_gmt] => 2020-02-27 10:55:11
    [post_content] => 
    [post_title] => MyTeam
    [post_excerpt] => 
    [post_status] => publish
    [comment_status] => closed
    [ping_status] => closed
    [post_password] => 
    [post_name] => allus-cu
    [to_ping] => 
    [pinged] => 
    [post_modified] => 2020-08-24 19:03:02
    [post_modified_gmt] => 2020-08-24 19:03:02
    [post_content_filtered] => 
    [post_parent] => 844   // This value is not correct
    [guid] => https://train.localdev.com/?post_type=wc_memberships_team&p=84887
    [menu_order] => 0
    [post_type] => wc_memberships_team
    [post_mime_type] => 
    [comment_count] => 0
    [filter] => db
)

I have checked in Database and in database, post_parent value is updated one.

Complete Code in all together:

global $wpdb;
$table_name = $wpdb->prefix . "posts";
$add_plan_to_team = $wpdb->update( $table_name, array( 'post_parent' => '370' ), array('ID'=> '84887'));

if($add_plan_to_team){
    $post = get_post( $team_id, 'OBJECT', 'db' );
    echo '<h1> team_updated </h1>';
    print_r($post);            
}

Please tell me how can i fix it.

I have a post and i need to update its post_parent. So i have used following to update the post value. Old Post ID is 844 and using query i have updated the value to 370 using below:

    global $wpdb;
    $table_name = $wpdb->prefix . "posts";
    $add_plan_to_team = $wpdb->update( $table_name, array( 'post_parent' => '370' ), array('ID'=> '84887'));
    // UPDATE wp_posts SET post_parent=370 WHERE ID=84887 

On next screen, i need to get the post above post and then perform some functions. I am doing it like this

     $post = get_post( 84887 );

But instead of returning updated values, i am getting the old post_parent value in return. Like below

WP_Post Object
(
    [ID] => 84887
    [post_author] => 2
    [post_date] => 2020-02-27 10:55:11
    [post_date_gmt] => 2020-02-27 10:55:11
    [post_content] => 
    [post_title] => MyTeam
    [post_excerpt] => 
    [post_status] => publish
    [comment_status] => closed
    [ping_status] => closed
    [post_password] => 
    [post_name] => allus-cu
    [to_ping] => 
    [pinged] => 
    [post_modified] => 2020-08-24 19:03:02
    [post_modified_gmt] => 2020-08-24 19:03:02
    [post_content_filtered] => 
    [post_parent] => 844   // This value is not correct
    [guid] => https://train.localdev.com/?post_type=wc_memberships_team&p=84887
    [menu_order] => 0
    [post_type] => wc_memberships_team
    [post_mime_type] => 
    [comment_count] => 0
    [filter] => db
)

I have checked in Database and in database, post_parent value is updated one.

Complete Code in all together:

global $wpdb;
$table_name = $wpdb->prefix . "posts";
$add_plan_to_team = $wpdb->update( $table_name, array( 'post_parent' => '370' ), array('ID'=> '84887'));

if($add_plan_to_team){
    $post = get_post( $team_id, 'OBJECT', 'db' );
    echo '<h1> team_updated </h1>';
    print_r($post);            
}

Please tell me how can i fix it.

I have a post and i need to update its post_parent. So i have used following to update the post_parent value. Old post_parent is 844 and using query i have updated the value to 370 using below:

    global $wpdb;
    $table_name = $wpdb->prefix . "posts";
    $add_plan_to_team = $wpdb->update( $table_name, array( 'post_parent' => '370' ), array('ID'=> '84887'));
    // UPDATE wp_posts SET post_parent=370 WHERE ID=84887 

On next screen, i need to get the post above post and then perform some functions. I am doing it like this

     $post = get_post( 84887 );

But instead of returning updated values, i am getting the old post_parent value in return. Like below

WP_Post Object
(
    [ID] => 84887
    [post_author] => 2
    [post_date] => 2020-02-27 10:55:11
    [post_date_gmt] => 2020-02-27 10:55:11
    [post_content] => 
    [post_title] => MyTeam
    [post_excerpt] => 
    [post_status] => publish
    [comment_status] => closed
    [ping_status] => closed
    [post_password] => 
    [post_name] => allus-cu
    [to_ping] => 
    [pinged] => 
    [post_modified] => 2020-08-24 19:03:02
    [post_modified_gmt] => 2020-08-24 19:03:02
    [post_content_filtered] => 
    [post_parent] => 844   // This value is not correct
    [guid] => https://train.localdev.com/?post_type=wc_memberships_team&p=84887
    [menu_order] => 0
    [post_type] => wc_memberships_team
    [post_mime_type] => 
    [comment_count] => 0
    [filter] => db
)

I have checked in Database and in database, post_parent value is updated one.

Complete Code in all together:

global $wpdb;
$table_name = $wpdb->prefix . "posts";
$add_plan_to_team = $wpdb->update( $table_name, array( 'post_parent' => '370' ), array('ID'=> '84887'));

if($add_plan_to_team){
    $post = get_post( $team_id, 'OBJECT', 'db' );
    echo '<h1> team_updated </h1>';
    print_r($post);            
}

Please tell me how can i fix it.

Source Link
Loading