Create Page/Post

Programmatically Create Page or post:

sample call :
ID;
//$slug = ‘shopping-cart’;
//$title = ‘Shopping Cart’;
// If the page doesn’t already exist, then create it
if( null == get_page_by_title( $title ) ) {
// Set the post ID so that we know the post was created successfully
$page_id = wp_insert_post(
array(
‘comment_status’ => ‘closed’,
‘ping_status’ => ‘closed’,
‘post_author’ => $author_id,
‘post_name’ => $slug,
‘post_title’ => $title,
‘post_status’ => ‘publish’,
‘post_type’ => $post_type,
‘post_content’ => $page_content,
‘post_parent’=>0
)
);
// Otherwise, we’ll stop
} else {
// Arbitrarily use -2 to indicate that the page with the title already exists
$page_id = -2;
} // end if
return $page_id;
} // end programmatically_create_post

No Comments

Post a Comment