BuddyDev

Search

buddyblog display posts and custom post type at the same time

Tagged: 

  • Participant
    Level: Initiated
    Posts: 10
    richard gueron on #637

    Hello Brajesh and thank you for your plugin!

    Actually with buddyblog i can display on user’s profile every post this user created but i want to display as well all entries created by the user as custom post type too
    Unfortunatly in buddyblog’s options you could only choose post or custom post, not both at the time.

    Is it possible to display both because i am stuck right now ?

    Thank you!

  • Keymaster
    (BuddyDev Team)
    Posts: 24149
    Brajesh Singh on #638

    Hi Richard,
    Welcome to BuddyDev forum.

    If you are only concerned about displaying then I can easily guide you. If you want to allow users to write posts for multiple post type then BuddyPress can not handle that. The limitation is due to the need of different UI for allowing creating posts and having separate forms for each of these.

    Please do let me know if you just need to display it.

  • Participant
    Level: Initiated
    Posts: 10
    richard gueron on #639

    Hello Brajesh 😉

    No i only want to display both regulars posts and custom post type on their profil. I use gravity form in front end for users to be able to write their post and custom post type.

    Do i need to modify a core file of your plugin?

    Thank you

  • Participant
    Level: Initiated
    Posts: 10
    richard gueron on #644

    Maybe i must use a function to override without modify core files?

  • Keymaster
    (BuddyDev Team)
    Posts: 24149
    Brajesh Singh on #647

    Hi Richard,
    Apologies for the delayed reply.

    No change in the plugin core file is required.
    Please copy buddyblog/templates/buddyblog to your theme/buddyblog
    Those are template files. Then,open posts.php and change this line

    
        $query_args = array(
    		'author'        => bp_displayed_user_id(),
    		'post_type'     => buddyblog_get_posttype(),
    		'post_status'   => $status,
    		'paged'         => intval( $paged )
        );
    

    to

    
    
        $query_args = array(
    		'author'        => bp_displayed_user_id(),
    		'post_type'     => array( 'post', buddyblog_get_posttype(), 'other-post-type'),//all post types
    		'post_status'   => $status,
    		'paged'         => intval( $paged )
        );
    

    That will make it list everything. Same goes for buddyblog/single.php

    Hope that helps.

  • Participant
    Level: Initiated
    Posts: 10
    richard gueron on #651

    Hello and thank you Brajesh.

    it s working but inotice 2 things;

    – In order this to work, you need in buddyblog setting to change blog post type from post to custom post type name (for me it was “Concours”). If not, it will not display custom post type but only posts.

    – Next to the posts tab in submenu, the number display is not accurate. In my case for exemple i have 6 posts (3 regular and 3 custom post type) and it mark only (3)

  • Keymaster
    (BuddyDev Team)
    Posts: 24149
    Brajesh Singh on #658

    Hi Richard,

    Thank you

    1. You are right about that. The reason is I used ‘buddyblog_get_posttype()’ in the array. You can replace that by the custom post type and it won’t need you to select them in the settings.

    2. This requires a change in core file, Please open buddyblog-functions.php and on line 58

    change

    
    $count = $wpdb->get_var( $wpdb->prepare( "SELECT count('*') FROM {$wpdb->posts} WHERE post_author=%d AND post_type=%s AND (post_status='publish'||post_status='draft')", $user_id, buddyblog_get_posttype() ) );
    
    

    to

    
    $count = $wpdb->get_var( $wpdb->prepare( "SELECT count('*') FROM {$wpdb->posts} WHERE post_author=%d AND (post_status='publish'||post_status='draft')", $user_id ) );
    
    

    That will do it.

  • Participant
    Level: Initiated
    Posts: 10
    richard gueron on #736

    Thank you Brajesh!

    1. so basicly i must write it like this ?

    $query_args = array(
    ‘author’ => bp_displayed_user_id(),
    ‘post_type’ => array( ‘post’, ‘name of the custom post type’, ‘other-post-type’),//all post types
    ‘post_status’ => $status,
    ‘paged’ => intval( $paged )
    );

    2. the code you provide doesn’t work for me. the number is now ‘123’ whereas i have only 6 posts (3 normal post and 3 custom post)

    Thank you for your time

  • Keymaster
    (BuddyDev Team)
    Posts: 24149
    Brajesh Singh on #743

    Hi Richard,

    1. Yes

    2. Currently, I was not filtering for post types, so most probably you are checking for admin account and even the pages are being listed there. If you want to query only for a few post types, you will need to modify that query and add something liek this

    post_type =’post__type1′ || post_type=’post_type2′ etc. If you can provide me the post types you need, i will supply the complete query.

  • Participant
    Level: Initiated
    Posts: 10
    richard gueron on #746

    of course! custom post type is call “Concours”

    Thank you Brajesh!

You must be logged in to reply to this topic.

This topic is: not resolved