BuddyDev

Search

[Resolved] [Blog categories for groups] Blogs are visible in Google!

  • Participant
    Level: Master
    Posts: 152
    Hugo Callens on #17846

    I created some blog posts in a particular Buddypress group and now notice that the posts are publicly visible in Google.
    I thought the post could only be viewed by a logged in group member?
    Please help me, this is really urgent!

    • This topic was modified 6 years, 2 months ago by Hugo Callens.
  • Keymaster
    (BuddyDev Team)
    Posts: 24706
    Brajesh Singh on #17862

    Hi Hugo,
    I am sorry for the inconvenience.

    The posts visibility is governed by normal WordPress reading settings.

    If you are using a seo plugin, exclude the categories used by groups from the indexable list.

    If you need to remove the post from normal posts list(your blog section), we can use pre_get_posts to exclude posts from a group in the actual stream and then make it only visible to the group members.

    Regards
    Brajesh

  • Participant
    Level: Master
    Posts: 152
    Hugo Callens on #17863

    Yes I would like to restrict the visibility to logged in group members only.
    So posts in category A can only be seen by group A, posts in category B only by group B etc. and are not to be found in Google.
    How can I do that, using pre_get_posts you mentioned?

  • Keymaster
    (BuddyDev Team)
    Posts: 24706
    Brajesh Singh on #17864

    Hi Hugo,

    Thank you.

    I will post the code in around two hours when I will be back to work.

    Regards
    Brajesh

  • Keymaster
    (BuddyDev Team)
    Posts: 24706
    Brajesh Singh on #17889

    Hi Hugo,

    Please add it in your bp-custom.php

    
    
    /**
     * Redirect to group post if needed.
     */
    function buddydev_redirect_to_group_post() {
    
    	if ( ! function_exists( 'bcg_get_post_type' ) || ! is_singular( bcg_get_post_type() ) ) {
    		return;
    	}
    
    	$post_id  = get_queried_object_id();
    	$group_id = get_post_meta( $post_id, '_bcg_group_id', true );
    	if ( $group_id && ! bp_is_group() ) {
    
    		$post      = get_post( $post_id );
    		$permalink = bp_get_group_permalink( groups_get_group( $group_id ) ) . BCG_SLUG . '/' . $post->post_name;
    
    		bp_core_redirect( $permalink, 301 );
    	}
    }
    add_action( 'bp_template_redirect', 'buddydev_redirect_to_group_post' );
    
    /**
     * Exclude the group posts from everywhere else.
     *
     * @param WP_Query $query query object.
     */
    function buddydev_filter_out_bcg_posts( $query ) {
    
    	if ( is_admin() || ! function_exists( 'bcg_get_post_type' ) ) {
    		return;
    	}
    
    	// Not our post type or inside the group.
    	if ( bcg_get_post_type() != $query->get( 'post_type' ) || bp_is_group() ) {
    		return;
    	}
    
    	$args = $query->query_args;
    
    	if ( isset( $args['meta_query'] ) ) {
    		$meta_query = $args['meta_query'];
    	} else {
    		$meta_query = array();
    	}
    
    	// now, we add our own condition.
    	$meta_query[] = array(
    		'key'     => '_is_bcg_post',
    		'value'   => '1', // not needed.
    		'compare' => 'NOT EXISTS',
    	);
    
    	$query->set( 'meta_query', $meta_query );
    }
    
    add_action( 'pre_get_posts', 'buddydev_filter_out_bcg_posts' );
    
    

    Please do note that it does not check for categories. Instead, It checks if the post was created from group interface and does the needed.

    Regards
    Brajesh

  • Participant
    Level: Master
    Posts: 152
    Hugo Callens on #17897

    OK, thank you!
    So a post with category A assigned, but created outside of group A (e.g. imported from another blog or existing post given a new category) will still be publicly visible, is that right?

  • Keymaster
    (BuddyDev Team)
    Posts: 24706
    Brajesh Singh on #17899

    Hi Hugo,
    That’s correct.

    You can make any post invisible from stream by adding the meta key

    _is_bcg_post
    

    But in order to properly redirect(If a post is accessed directly), we need the associated group too.

    That should be stored as the numeric value in another meta

    
    _bcg_group_id
    

    So, if you are importing, please make sure to have these two values.

    Regards
    Brajesh

  • Participant
    Level: Master
    Posts: 152
    Hugo Callens on #17900

    Where exactly should I add these keys (I am not a programmer)?

  • Keymaster
    (BuddyDev Team)
    Posts: 24706
    Brajesh Singh on #17904

    Hi Hugo,
    The above steps is only needed if you are importing posts. Posts created with BCG don’t need it.

    In order to add it, you will need to know the group id.

    Hoe are you importing the post?

  • Participant
    Level: Master
    Posts: 152
    Hugo Callens on #17905

    I exported an XML from an external site and then imported in into my BP site through WP Importer.

You must be logged in to reply to this topic.

This topic is: resolved