Home › Forums › Calendar Products › Filter Bar › Queries being overridden by pre_get_posts
- This topic has 3 replies, 3 voices, and was last updated 10 years, 8 months ago by
Support Droid.
-
AuthorPosts
-
August 12, 2015 at 6:03 am #995340
Craig
ParticipantHi
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 URLIf 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
AndyAugust 12, 2015 at 7:26 am #995400Craig
ParticipantFor 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
AndyAugust 12, 2015 at 8:19 am #995439Brian
MemberI 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!
August 27, 2015 at 7:05 am #999533Support Droid
KeymasterThis 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. -
AuthorPosts
- The topic ‘Queries being overridden by pre_get_posts’ is closed to new replies.
