Wouter den Ouden
Wouter den Ouden

Reputation: 1523

WordPress insert_post without title

On the register_activation_hook of my plugin I am adding a post with the following code.

$details_page = array(
    'post_title'    => 'details',
    'post_content'  => '[auto]',
    'post_type'     => 'page',
    'post_status'   => 'publish',
    'post_author'   => 1,
    'post_category' => array( 3,4 )
);
wp_insert_post($details_page);

It adds the post with the right shortcode in it. But now I want to delete the word "Details" on the page. (the post title).

I don't know how to do this. I thought of getting the post by name in the registration hook and then delete the Title. But I don't know how.

Upvotes: 2

Views: 338

Answers (1)

Wouter den Ouden
Wouter den Ouden

Reputation: 1523

Found the solution..

$details_page = array(
    'post_title'    => '',
    'post_name'     => 'details',
    'post_content'  => '[auto]',
    'post_type'     => 'page',
    'post_status'   => 'publish',
    'post_author'   => 1,
    'post_category' => array( 3,4 )
);
wp_insert_post($details_page);

the post_title could be empty if you use post_name instead

Upvotes: 1

Related Questions