i tried to generate a page via wp_insert_post. That works fine except that the post_name is always written with the same value as the post_title.
Here comes the code snippet:
// Create homesite if not exists
$ins_home = array(
'post_title' => 'Home',
'post_name' => 'my-home-site',
'post_status' => 'publish',
'post_type' => 'page',
'comment_status' => 'closed',
'ping_status' => 'closed'
);
$result = $wpdb->query("SELECT wpost.post_name FROM $wpdb->posts wpost WHERE wpost.post_name = 'my-home-site'");
if($result < 1){// Insert the post into the database
$page_id = wp_insert_post( $ins_home );
}
Any help is very appreciated.
Thanks a lot,
Joe
Gr8 job… only thing missing is the action and the timing for it to work…
try this:
.
EDIT
According to the Source code of wp_insert_post
So… if post_status not in array… post_name = post_title (sanitized ofCourse)
So… altough i am very short on time to check it today you should try to envelope
the ‘publish’ post_status with an aray – see my revised code
.
i hope this solves it… please try it and share results