在运行wp_INSERT_POST之前检查是否有重复的自定义字段值

时间:2014-05-04 作者:suascat

也就是说,我希望在创建帖子之前检查“guid\\u review”ACF值,以防止其重复。

foreach ($items as $itemKey => $item) {


            $myPost = array(
                \'post_type\' => \'client_review\',
                \'post_title\' =>(string) $item->title, //the object as a string before attempting to manipulate it.
                \'post_content\' =>(string) $item->description                

            );


            $inserted_post_id = wp_insert_post( (array) $myPost );



            if( $inserted_post_id ){

                add_post_meta( (int) $inserted_post_id,\'guid_review\',(string)$item->guid);
                add_post_meta($inserted_post_id,\'link_review\',(string)$item->link);
                add_post_meta($inserted_post_id,\'author_review\',(string)$item->author);
                add_post_meta($inserted_post_id,\'rating_review\',(string)$item->children(\'d3\', true)->rating);
                add_post_meta($inserted_post_id,\'certified_review\',(string)$item->children(\'d3\', true)->certified);
                add_post_meta($inserted_post_id,\'pub_date_review\',(string)$item->pubDate);              

            }

            }

1 个回复
SO网友:Aveesh

您可以运行WP_query 使用meta_keymeta_value 参数

看看这里WP_User_Query

如果结果为非空-您知道您有一个副本!

结束

相关推荐

在运行wp_INSERT_POST之前检查是否有重复的自定义字段值 - 小码农CODE - 行之有效找到问题解决它

在运行wp_INSERT_POST之前检查是否有重复的自定义字段值

时间:2014-05-04 作者:suascat

也就是说,我希望在创建帖子之前检查“guid\\u review”ACF值,以防止其重复。

foreach ($items as $itemKey => $item) {


            $myPost = array(
                \'post_type\' => \'client_review\',
                \'post_title\' =>(string) $item->title, //the object as a string before attempting to manipulate it.
                \'post_content\' =>(string) $item->description                

            );


            $inserted_post_id = wp_insert_post( (array) $myPost );



            if( $inserted_post_id ){

                add_post_meta( (int) $inserted_post_id,\'guid_review\',(string)$item->guid);
                add_post_meta($inserted_post_id,\'link_review\',(string)$item->link);
                add_post_meta($inserted_post_id,\'author_review\',(string)$item->author);
                add_post_meta($inserted_post_id,\'rating_review\',(string)$item->children(\'d3\', true)->rating);
                add_post_meta($inserted_post_id,\'certified_review\',(string)$item->children(\'d3\', true)->certified);
                add_post_meta($inserted_post_id,\'pub_date_review\',(string)$item->pubDate);              

            }

            }

1 个回复
SO网友:Aveesh

您可以运行WP_query 使用meta_keymeta_value 参数

看看这里WP_User_Query

如果结果为非空-您知道您有一个副本!

相关推荐