Home › Forums › Calendar Products › Events Calendar PRO › Including Events in Main WP_Query
- This topic has 4 replies, 3 voices, and was last updated 10 years, 6 months ago by
George.
-
AuthorPosts
-
October 4, 2015 at 6:01 pm #1011300
Gary
ParticipantSo, I want to include events in my main loop, but ONLY if they’re from one particular organizer.
This is the query alteration I’ve written, but it’s not working.
function alter_query_jrr($qry) {
if ( $qry->is_main_query()) {
$qry->set(‘post_type’,array(‘tribe_events’,’posts’));
$qry->set(‘tribe_organizer’,3690);
}
}
add_action(‘pre_get_posts’,’alter_query_jrr’);What I want the loop to include is my posts and events from only 1 organizer…
I searched the pre_get_posts docs and just can’t wrap my head around how I’d format that.Thanks in advance for help or direction…
October 5, 2015 at 10:57 pm #1011746George
ParticipantHey Gary!
There are two things about your question that, unfortunately, make it a bit hard to answer completely: first is that your question relates to custom coding, for which we don’t technically offer any support, but secondly (and mainly) is that specifying a taxonomy in pre_get_posts() is a bit tricky. It’s possible, but just tricky.
If you’re familiar with ‘tax_query’ in WordPress’ WP_Query class, then essentially all you’ll be doing is using that same array format of taxonomy rules and applying it to the query. You should be able to use tax_query to write the organizer-filtering rules you would like. If you’re unfamiliar with tax_query, you can read about it in depth in the “Taxonomy Parameters” section of this article here → https://codex.wordpress.org/Class_Reference/WP_Query
If you’re interested in some code examples and such, there are fortunately many out there for this problem. I found a good one here, for example, if you’re curious → http://wordpress.stackexchange.com/questions/35196/theres-a-way-to-use-query-settax-query-in-pre-get-posts-filter
I hope all of this information helps!
— George
October 6, 2015 at 8:39 am #1011936Gary
ParticipantGeorge,
Thanks! I wasn’t sure if this would elicit a response as it was custom. So I appreciate the answer and the links.
I was just having an awful time trying to figure out how to phrase that question in a more general way to pull search results…
Thanks
GaryOctober 7, 2015 at 2:03 pm #1012490Nico
MemberHey Gary,
George is sick today, but thanks! We’re glad you’re sorted!
I’ll go ahead and close out this thread, but if you need help with anything else please don’t hesitate to create a new one and we will be happy to assist you.
Best,
NicoOctober 9, 2015 at 7:59 am #1013152George
ParticipantNico was right here, I unfortunately caught a pretty bad cold and wasn’t able to reply in a timely fashion. I’m sorry about that! But I’m glad that my response was somewhat helpful to begin with.
Thanks for covering for me a bit, too, Nico! 🙂
Cheers,
George -
AuthorPosts
- The topic ‘Including Events in Main WP_Query’ is closed to new replies.
