我有一篇帖子,我需要更新它的post\\u父级。因此,我使用以下代码来更新post\\u parent值。旧的post\\u父项为844,使用query,我已使用以下命令将值更新为370:
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
在下一行中,我需要获得帖子,然后执行一些功能。我就是这样做的
$post = get_post( 84887 );
但不是返回更新的值,而是返回旧的post\\u parent值。如下所示
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
)
我已经签入了数据库,在数据库中,post\\u parent值更新了一个。
完整的代码:
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);
}
请告诉我如何修理它。