I’ve made so that everytime my plugin is activated it’s supposed to create a page. Although i want it to only create the page if it doesn’t exist from before. But what it’s doing is that it’s creating another page with kns-products-1 instead of not doing it at all.
My code so far:
function kns_install() {
global $wp_version;
if( version_compare( $wp_version, '3.5', '<' ) ) {
wp_die( 'Detta tilläget kräver att du har WordPress version 3.5 eller högre.' );
} else {
if(!is_page('kns-products')) {
$product_page = array(
'post_type' => 'page',
'post_name' => 'kns-products',
'post_title' => 'Produkter',
'post_status' => 'publish',
);
wp_insert_post($product_page);
}
}
}
I thought that the !is_page condition would solve this but there seems to be a built in code to just add numbers after the slug name.
Is there any way to solve this or does anyone know of any better approach?