admin管理员组文章数量:1327843
I m working on a wp plugin and i have 3 tables. In my plugin i have two different loop: both of them create programmatically a page from my tables. My problem is that if i refresh the page, it duplicate my pages. How can i avoid this? I have tried with get post title but it not work. Here my loop
for ($i = 0; $i < count($namepages); $i++) {
mic_create_new_page($name[$i],$namepages[$i]);
}
foreach ( $resu as $res ) {
$id = $res->id;
$keyword = strtolower(str_replace(" ","-",$res->keyword));
$secteur = strtolower(str_replace(" ","-",$res->libelle));
mic_create_new_page_key_sec($keyword, $secteur, $id);
}
and that s my functions
function mic_create_new_page_key_sec($keyword, $secteur, $id) {
global $user_ID;
$new_post = array(
'post_title' => ucfirst($keyword) . " " . ucfirst($secteur),
'post_content' => '[makeitseo-keyword-secteur]',
'post_status' => 'publish',
'post_date' => date('Y-m-d H:i:s'),
'post_author' => $user_ID,
'post_type' => 'page',
'post_name' => $keyword ."-".$secteur."-k".$id
);
$post_id = wp_insert_post($new_post);
}
function mic_create_new_page($name, $namepages) {
global $user_ID;
$new_post = array(
'post_title' => 'Services ' . $name,
'post_content' => '[makeitseo-keyword]',
'post_status' => 'publish',
'post_date' => date('Y-m-d H:i:s'),
'post_author' => $user_ID,
'post_type' => 'page',
'post_name' => $namepages
);
$post_id = wp_insert_post($new_post);
}
本文标签: phpHow can i avoid duplicate same post in wp
版权声明:本文标题:php - How can i avoid duplicate same post in wp? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742219685a2435218.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论