Exclude particular tag from widget list

Home Forums Calendar Products Events Calendar PRO Exclude particular tag from widget list

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1120298
    Fabrice
    Participant

    Hello,
    I’m trying to exclude a particular tag term from an instance of a widget list… I saw that the settings of the widget allows me to add filter, but not to exclude. I’ve tried your shortcodes too (by adding a “-” in front of a slug or of a term id) but it is not working either (this would be handy by the way !). So I’ve been trying to use a preget post but with no success so far as I’m not sure how to target the widget instance: I’m trying a wordpress function, is_active_widget() and I’m not sure either how to use preget post for the query of that particular instance. So far I get to the following code any hint would be welcome !
    Thank you.

    function exclude_tag( $query ){
    if ( is_active_widget( 'tribe-events-adv-list-widget-2') ) {
    $taxquery = array(
    array(
    'taxonomy' => 'post_tag',
    'field' => 'id',
    'terms' => array( 36 ), //the ID of the event tag
    'operator'=> 'NOT IN'
    )
    );

    $query->set('tax_query', $taxquery);

    return;

    }

    }

    #1120400
    George
    Participant

    Hey Fabrice,

    Thanks for reaching out! I must inform you that we cannot help out with code-level questions like this. 🙁 So, you will have to research this stuff on your own and/or hire the assistance of a professional developer to help you realize the changes you want to make.

    Please read this page to learn more about this ? https://theeventscalendar.com/knowledgebase/what-support-is-provided-for-license-holders/


    Now, while what I wrote above is true, and you will have to take the reins on these customizations, I did want to at least help out a little bit! 😀

    For starters, I would like to point out a filter you can use that specifically targets the query args for the list widget.

    That filter is called tribe_events_list_widget_query_args

    You can see it in action—and should look at it to get an understanding of its role and context—at this file in your copy of The Events Calendar:

    /the-events-calendar/src/Tribe/List_Widget.php

    With that filter you could write custom code like this:


    add_filter( 'tribe_events_list_widget_query_args', 'fabrice_widget_custom_tax_query' );

    function fabrice_widget_custom_tax_query( $args ) {

    $args['tax_query'] = array(
    array(
    'taxonomy' => 'post_tag',
    'field' => 'id',
    'terms' => array( 36 ),
    'operator' => 'NOT IN'
    )
    );

    return $args;
    }

    ☝️ As noted, this may need more custom work on your part, but I hope it helps get you started!

    Cheers,
    George

    #1120552
    Fabrice
    Participant

    Ok, thanks ! we will try…

    #1120615
    George
    Participant

    Nice. Best of luck with your custom coding, @Fabrice!

    Cheers,
    George

Viewing 4 posts - 1 through 4 (of 4 total)
  • The topic ‘Exclude particular tag from widget list’ is closed to new replies.