Correct way to exclude a category from related events

Home Forums Calendar Products Events Calendar PRO Correct way to exclude a category from related events

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #930164
    derekshirk
    Participant

    I it looks like thee is a funciton tribe_get_related_posts that returns the related posts/events for a single event. How would I go about hooking into or filtering that function to remove a specific category (category id = 18).

    Thanks.

    #930175
    Brian
    Member

    Hi,

    Thanks for using our plugins. I can help you out with this.

    We have a filter called:

    tribe_related_posts_args

    That filers the arguments for the Related Event Query.

    You could use that to add an exclude for a category.

    The function that filter is in is called:

    tribe_get_related_posts

    And found in this file:

    events-calendar-pro\public\template-tags\general.php

    Let me know if you have any follow up questions.

    Thanks

    #930186
    derekshirk
    Participant

    OK, that is helpful. Not I need to figure out how to property write the filter. would I do something like this?

     add_action( 'tribe_get_related_posts_args', 'excl_category_from_related' );
         
        function excl_category_from_related() {
            
            $args = array(
                'cat' => -18,
                );
    
            return $args ;
        }
    #930356
    Brian
    Member

    I think it would be closer to this as you have to use a filter not an action for this:

    add_filter( 'tribe_get_related_posts_args', 'excl_category_from_related', 10, 1 );

    function excl_category_from_related( $args ) {

    $args['cat'] = -18;

    return $args ;
    }

    That is untested though so it may not work.

    This section the is where I would see the problems happening first:

    $args[‘cat’] = -18;

    #938487
    Brian
    Member

    Since I haven’t heard back from you here, I’m going to go ahead and close out this thread. Feel free to start a new thread if you have further issues. Thanks! 🙂

Viewing 5 posts - 1 through 5 (of 5 total)
  • The topic ‘Correct way to exclude a category from related events’ is closed to new replies.