BuddyDev

Search

[Resolved] Can I separate the users' blog posts from the main site (BuddyBlog)?

Tagged: 

  • Participant
    Level: Initiated
    Posts: 9
    dm484 on #34515

    I am building a social media website using BuddyPress, and I have installed the BuddyBlog plugin. The main website has a blog menu (let’s call it “main blog”), which I intend to only include “good quality posts.” In the meantime, I would like the users to have their own blogs. Right now, if they add a new post to their blog page, the post automatically shows up on the “main blog.”

    In sum, is there any way that I can separate user blog from the main blog? Thanks!

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2935
    Ravi on #34526

    Hello,

    Thank you for posting. Try using the following code.

    
    
    /**
     * Exclude user posts
     *
     * @param WP_Query $query Query object.
     */
    function buddydev_exclude_user_posts( $query ) {
    
    	if ( ! is_main_site() || ! function_exists( 'buddyblog' ) ) {
    		return;
    	}
    
    	if ( ! $query->is_main_query() ) {
    		return;
    	}
    
    	$meta_query = $query->get( 'meta_query' );
    
    	if ( $meta_query ) {
    		$meta_query[] = array(
    			'key'     => '_is_buddyblog_post',
    			'value'   => 1,
    			'compare' => 'NOT EXISTS'
    		);
    	} else {
    		$meta_query = array(
    			array(
    				'key'     => '_is_buddyblog_post',
    				'value'   => 1,
    				'compare' => 'NOT EXISTS'
    			)
    		);
    	}
    
    	$query->set( 'meta_query', $meta_query );
    }
    add_action( 'pre_get_posts', 'buddydev_exclude_user_posts' );
    
    

    Let me know if it works or not.

    Regards
    Ravi

  • Participant
    Level: Initiated
    Posts: 9
    dm484 on #34544
    This reply has been marked as private.
  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2935
    Ravi on #34548

    Hello,

    Thank you for the acknowledgment. Marking as resolved.

    Regards
    Ravi

You must be logged in to reply to this topic.

This topic is: resolved