I m working on a plugin and i would add a page for every value of my database.
But for every refresh, a new page with same name will be added. How can i fix this?
for ($i = 0; $i < count($namepages); $i++) {
mic_create_new_page($name[$i],$namepages[$i]);
}
function mic_create_new_page($name, $namepages) {
global $user_ID;
if (post_exists($namepages) == false) {
$new_post = array(
'post_title' => 'Services ' . $name,
'post_content' => 'New post content',
'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);
}
}
register_activation_hook(__FILE__, 'create_new_page');