Support » Theme: P2 » Assigning P2 to a custom post type

  • I’d like to have the P2 status updates sent/saved to a custom post type as I will be integrating P2 into an existing theme.

Viewing 1 replies (of 1 total)
  • Hi Chris,

    take a look at /inc/ajax.php – at the very bottom there’s a block that inserts the post. By default it looks like this:


    $post_id = wp_insert_post( array(
    'post_author' => $user_id,
    'post_title' => $post_title,
    'post_content' => $post_content,
    'post_type' => 'post',
    'tags_input' => $tags,
    'post_status' => 'publish'
    ) );

    In post_type you can change this to your heart’s content. You can even add other attributes as described here: http://codex.wordpress.org/Function_Reference/wp_insert_post

    For example, you could change this to ‘post_type’ => ‘page’, and then all posts will become pages. Note those won’t show up on the front page of course.

    To limit this change only to status updates, wrap the block into an if/then statement, like so:


    if ($post_format == 'status') {
    $post_id = wp_insert_post( array(
    'post_author' => $user_id,
    'post_title' => $post_title,
    'post_content' => $post_content,
    'post_type' => 'page',
    'tags_input' => $tags,
    'post_status' => 'publish'
    ) );

    } else {
    $post_id = wp_insert_post( array(
    'post_author' => $user_id,
    'post_title' => $post_title,
    'post_content' => $post_content,
    'post_type' => 'post',
    'tags_input' => $tags,
    'post_status' => 'publish'
    ) );
    }

    Hope this helps!

Viewing 1 replies (of 1 total)
  • The topic ‘Assigning P2 to a custom post type’ is closed to new replies.