WordPress.org

Ready to get started?Download WordPress

Forums

P2
Assigning P2 to a custom post type (2 posts)

  1. villagechris
    Member
    Posted 9 months ago #

    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.

  2. Jay Versluis
    Member
    Posted 9 months ago #

    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!

Reply

You must log in to post.

About this Theme

About this Topic

Tags

No tags yet.