Home › Forums › Calendar Products › Events Calendar PRO › Event bar query customization
- This topic has 3 replies, 2 voices, and was last updated 11 years, 2 months ago by
Barry.
-
AuthorPosts
-
March 9, 2015 at 3:26 pm #947090
Stephen
ParticipantHi, I’m trying to add some custom filters to the events bar and found this chunk of code here: https://theeventscalendar.com/knowledgebase/understanding-the-tribe-events-bar/
add_filter( ‘tribe_events_pre_get_posts’, ‘setup_my_bar_field_in_query’, 10, 1 );
function setup_my_bar_field_in_query( $query ){
if ( !empty( $_REQUEST[‘tribe-bar-my-field’] ) ) {
$query->query_vars[‘my_var’] = $_REQUEST[‘tribe-bar-my-field’];
}return $query;
}Can somebody give me more insight into what actually happens once this value is set in the query_vars array? Does it add a meta query to the main query with key->’my_var’ value->$_REQUEST[‘tribe-bar-my-field’] compare->’=’?
March 10, 2015 at 7:58 am #947233Barry
MemberHi Stephen!
So that example code is (deliberately) pretty generic and is unlikely to be much use by itself if it is used verbatim.
The idea though is that you have an opportunity to look at the current request and modify the query variables appropriately (what that means and how you would modify them in a real life case obviously depends on what you’re trying to achieve). Later on in the request those variables will be used when WordPress builds the actual SQL query used to retrieve posts/events.
A great resource to read through to gain a little more insight can be found on the WordPress codex:
codex.wordpress.org/Class_Reference/WP_Query
This kind of work is a relatively advanced customization so a solid working knowledge of WordPress and how queries are processed is definitely required.
Does that help at all/do you have any other specific questions about this? Though we may not be able to go in to too much depth here in the support forum we would certainly be keen to learn how we might expand the knowledgebase article you referenced (or else find out what other articles we might create to support it).
Thanks!
March 10, 2015 at 8:33 am #947260Stephen
ParticipantHi Barry,
Thank you! this helps a lot!
I wasn’t sure if query_vars was a wordpress thing or an event calendar specific thing. Thank you for pointing me to the right section of the codex to clear that up.
As far as improving the knowledgebase article, I think the easiest thing to do would be to include the WP_Query codex link somewhere in that section with a “for more information…” label or something like that.
Thanks again!
Stephen
March 10, 2015 at 9:01 am #947280Barry
MemberNoted! (…and, in general, if you have other ideas for improvements to our docs please don’t hesitate to let us know here or on our UserVoice page 🙂 )
Thanks again!
-
AuthorPosts
- The topic ‘Event bar query customization’ is closed to new replies.
