Queries being overridden by pre_get_posts

Home Forums Calendar Products Filter Bar Queries being overridden by pre_get_posts

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #995340
    Craig
    Participant

    Hi

    Im trying to create a new filter where by only tags that are on upcoming events are shown in the filter, not from past events, using the category.php as a template
    This all works fine apart from if I reload the page so that tribe_post_tag is now in the URL

    If this i there then any query I do is being overridden

    So for instance

    
    		$event_list_args = array(
    			'post_type' => 'tribe_events',
    			'posts_per_page' => -1
    		);
    		$event_list_query = new WP_Query( $event_list_args );

    This will only bring in the filtered query, even if I try to override the query with this where $term_arr is all my terms

    
    		$event_list_args = array(
    			'post_type' => 'tribe_events',
    			'posts_per_page' => -1,
    			'tax_query' => array(
    				array(
    					'taxonomy' => 'post_tag',
    					'field'    => 'slug',
    					'terms'    => $term_arr,
    				),
    			),
    		);
    		$event_list_query = new WP_Query( $event_list_args );

    I have tried with this

    
    		$venues = tribe_get_events(array(
    			'eventDisplay' => 'list',
    			'orderby' => 'EventStartDate',
    			'order' => 'asc',
    			'tag' => $term_string
    		));

    But even with a list of tags it still gets overridden

    How can I get around this as I need the filter to display all the tags I want not just from the filtered WP_Query?

    Cheers
    Andy

    #995400
    Craig
    Participant

    For anyone interested I had to put a pre_get_post in with a higher priority to override it so in my function I called

    
    // Add a pre_get_posts with a high priority
    		add_action( 'pre_get_posts', array( $this, 'alter_event_query' ), 99 );
    //  Get all events that are upcoming
    		$event_list_args = array(
    			'post_type' => 'tribe_events',
    			'posts_per_page' => -1
    		);
    		$event_list_query = new WP_Query( $event_list_args );
    // Remove the pre_get post
    		remove_action( 'pre_get_posts', array( $this, 'alter_event_query' ) );

    Then just reset my taxonomies in the query in pre_get_posts

    Cheers
    Andy

    #995439
    Brian
    Member

    I am glad to see you were able to figure it out and thanks for sharing.

    I am going to go ahead and close this ticket. If you have a similar issue or another in the future, please do not hesitate to create a new ticket.

    Thanks!

    #999533
    Support Droid
    Keymaster

    This topic has not been active for quite some time and will now be closed.

    If you still need assistance please simply open a new topic (linking to this one if necessary)
    and one of the team will be only too happy to help.

Viewing 4 posts - 1 through 4 (of 4 total)
  • The topic ‘Queries being overridden by pre_get_posts’ is closed to new replies.