我正在尝试创建 php 代码,但它对我不起作用。它必须检查我网站数据库中的“post_title”,然后如果不存在则“如果存在 {do} (while)”则创建帖子。请看我的代码
?php
include 'wp-config.php';
$id = "id";
$nu = "2";
$selectquery ="SELECT * FROM `wpop_posts` WHERE `post_title` = '$id$nu' ";
$selectresult=mysql_query($selectquery);
while(mysql_num_rows($selectresult)>0)
{
$errormsgnewemployee = '<p id=notification>it exist.</p>';
echo "$errormsgnewemployee";
++$nu;
echo" $nu";
};
if (!mysql_num_rows($selectresult)>0) {$my_post = array();
$my_post['post_title'] = $id .$nu;
$my_post['post_content'] = $shelma;
$my_post['post_status'] = 'publish';
$my_post['post_author'] = 1;
$my_post['post_category'] = array(8,39);
wp_insert_post( $my_post );
print 'thats good!';};
?>