Skip to:
Content
Pages
Categories
Search
Top
Bottom

get a replies parent forum


  • serks
    Participant

    @serks

    I need a way to find out what a replies parent forum is.

    Reason is because I have created members only forums in a specific way by integrating DAP (Digital Access Pass) conditional functions. All of this is working great but my problem is with the search function of bbpress.

    I need to filter the search so it doesn’t display replies that are under members only forums.
    So like, IF REPLY_ID IS CHILD OF FORUM_NAME-OR-ID, REPLY = MEMBERS-ONLY-REPLY.

    I don’t mind if it displays topics but I do not want people to see replies that are under members only forums if they are not a member.

    So I think the file I need to play with is loop-search-reply.php but I need some help with figuring out the code to do this.

    Thanks in advance to anyone who can help

Viewing 3 replies - 1 through 3 (of 3 total)
  • You probably want to look into WordPress’ ‘Conditional Tags’

    http://codex.wordpress.org/Conditional_Tags

    And then a list of bbPress’ conditional tags http://codex.bbpress.org/bbpress-conditional-tags/


    serks
    Participant

    @serks

    Thanks for response Stephan,
    I actually managed to do this by using some code in loop-search.php and I used the same code in loop-replies.php…heres the code that does it…

    
    <?php if(get_post_type() == 'reply'):?>
    
           <?php // CHECK IF THIS REPLY IS UNDER MEMBERS ONLY FORUM.
           $parent = array_reverse(get_post_ancestors($post->ID)); // get an array of all the parent pages in order from most distant to closest.
           $first_parent = get_page($parent[0]); //get the first page in the array, which is the most distant parent
           $int = apply_filters('the_ID', $first_parent->ID); //filter the $first_parent to get only the wordpress page/post ID, which is an integer like 49 or 565. store it as a variable $int
           ?>
    		
            <?php if($int == 48) :?>
    	        <?php // DISPLAY A MESSAGE SAYING THE REPLY IS HIDDEN ?>
    	        <?php if(!user_subscribed()):?>
    		        <?php //bbp_get_template_part( 'loop', 'search-reply-membersonly'); ?>
    		        <div class="hidden-forum-comment">This comment is only visible to subscribers. <a href="/join">Click here to subscribe.</a></div>
    	        <?php endif;?>
            <?php else :?>
                    <?php bbp_get_template_part( 'loop', 'search-reply'); ?>
            <?php endif ;?>
    
    <?php elseif(get_post_type() == 'forum'): ?>
    	<?php bbp_get_template_part( 'loop', 'search-forum'); ?>
    <?php elseif(get_post_type() == 'topic'): ?>	
    	<?php bbp_get_template_part( 'loop', 'search-topic'); ?>
    <?php endif;?>
    
    

    Hope i’ve pasted that correctly.
    48 is the ID of the Members Only Forum.
    !user_subscribed() is one of my own functions to check if a user is subscribed to a product with DAP (Digital Access Pass).

    If anyone needs more help with this just ask. Be happy to help.


    Stephen Edgar
    Moderator

    @netweb

    Cool, that will work, thanks for the follow up and code example :)

Viewing 3 replies - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.