Tagged: buddyblog
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!
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
Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic.
This topic is: resolved