Announcement

Announcement Module
Collapse
No announcement yet.

Ways to hide search results of the forum articles when user is not logged in.

Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Ways to hide search results of the forum articles when user is not logged in.

    I was wondering if it is possible to hide the search results (default/normal search result) for forums/topics/replies
    articles when user is not logged in. Would it be possible? I want forum contents to be accessible only for the
    logged in users.

    I know that it is possible to set Knowledge Base Category(ies) or articles to be accessible only for the Logged In Users.
    And this works great. Any KB contents that are set to be available only for Logged in Users do not appear in the
    default/normal search result.

    Click image for larger version

Name:	fffffff.png
Views:	2
Size:	3.6 KB
ID:	358
    I would like to do the same thing for forums/topics/relies articles. Would it be possible? If so, how should
    I configure the theme?

    Regarding the forum articles, I was able to prevent them to open when user is not logged in. I used other plugins,
    such as s2 member or Ultimate Member plugin to do that.

    However, I still need to prevent these articles to come out as the search result when user is not logged in.
    The title of "secret" topic still comes out when user runs the default search as the picture below shows.

    Click image for larger version

Name:	aaaaaaaaaaaaaaa.png
Views:	1
Size:	96.9 KB
ID:	356

    I know that by removing the forums/topics/replies from Default Live search target, they can be excluded from
    the search result.
    Click image for larger version

Name:	search.png
Views:	2
Size:	8.2 KB
ID:	357
    However, this would mean that these contents would not appear even when user is logged in.

    Do you know any ways to do that? I appreciate any tips, clues, advice.
    Attached Files
    Last edited by Michi; 02-14-2018, 03:01 AM.

  • #2
    Please add this below code inside child theme or function.php


    PHP Code:
      function manual_bbp_reply_search$reply_search ) {  
     if( 
    is_user_logged_in() == true ) {  
    $reply_search['exclude_from_search'] = false;  
    return 
    $reply_search;  }  }  
    add_filter'bbp_register_reply_post_type''manual_bbp_reply_search' );    

    function 
    manual_bbp_forum_search$forum_search ) {
     if( 
    is_user_logged_in() == true ) {  
    $forum_search['exclude_from_search'] = false;  
    return 
    $forum_search;  
    }  }  
    add_filter'bbp_register_forum_post_type''manual_bbp_forum_search' );

      function 
    manual_bbp_topic_search$topic_search ) {
     if( 
    is_user_logged_in() == true ) {    $topic_search['exclude_from_search'] = false;
       return 
    $topic_search;
    }  }
       
    add_filter'bbp_register_topic_post_type''manual_bbp_topic_search' ); 


    adding above code will display search result only when user is logged in.
    Last edited by Jabin Kadel; 02-16-2018, 06:14 AM.
    Best Regards,

    Jabin Kadel
    Founder & CEO
    WpSmartApps.com

    Comment


    • #3
      Hello Jabin

      Where is the code supposed to be inserted?
      I've inserted the code into the file below but nothing changes.
      /manual-child/functions.php

      Is the file name supposed to be function.php or functions.php?
      Anyway, I tried both but no success.

      Also, I'm wondering if the part below is correct, because the seems to set the results to be included if user is logged in.
      It does not seem to control that the unwanted results to be removed if user is not logged in. Anyway I can be wrong too in this regard.
      if( is_user_logged_in() == true ) { $topic_search['exclude_from_search'] = false;

      I appreciate if you could give me a little more information on this issue. thanks for your support.

      Comment


      • #4
        We found more connected codes responsible to make forum search disable for logged-in users, we will add this feature sooner. For the time you can apply below steps.
        1. Open functions.php located inside "themes/manual/framework/includes/"
        2. Search function name "manual_attachment_sh_clauses".
        3. You will see below code inside search function
          PHP Code:
                foreach ( $theme_options['manual-default-search-type-multi-select']  as $post_type ) {   if( $count == $comma '';   else $comma ',';     $post_typeIN .= "".$comma."'".$post_type."'";     if( $post_type == 'attachment' $add_attachOR " OR $wpdb->posts.post_status = 'inherit' ";   else $add_attachOR '';     $count++;   } 
        4. Replace above code with below

          PHP Code:
                foreach ( $theme_options['manual-default-search-type-multi-select']  as $post_type ) {       if( is_user_logged_in() == false &&  $post_type == 'forum' ) continue;     if( $count == $comma '';   else $comma ',';     $post_typeIN .= "".$comma."'".$post_type."'";     if( $post_type == 'attachment' $add_attachOR " OR $wpdb->posts.post_status = 'inherit' ";   else $add_attachOR '';     $count++;   } 
        This will do the magic.
        Best Regards,

        Jabin Kadel
        Founder & CEO
        WpSmartApps.com

        Comment

        Working...
        X