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