wp-combine-queries
wp-combine-queries copied to clipboard
Does not work when querying events and posts - Maybe event plugin issue?
Hi!
This is an awesome plugin. I've used it and it works great. This time, I'm trying something different and was wondering if you could perhaps shed some light.
I'm using Event Organiser for event management.
Using Combine Queries, I'm trying to query posts and events. I know Combine Queries is working because it works just fine when I'm not querying events.
` // ----------------- // Sub query #1: // ----------------- $args1 = [ 'post_type' => array( 'news' ), // 'fields' => 'ids', 'posts_per_page' => 100, ];
// -----------------
// Sub query #2:
// -----------------
$args2 = [
'post_type' => 'event',
'suppress_filters' => false,
// 'fields' => 'ids',
'posts_per_page' => 100,
];
// ---------------------------
// Combined queries #1 + #2:
// ---------------------------
$args = [
'combined_query' => [
'args' => [ $args1, $args2 ],
'union' => 'UNION',
'posts_per_page' => 12,
'post_status' => 'publish',
// 'orderby' => 'none',
],
];
// ---------
// Output:
// ---------
$query = new WP_Query( $args );`
This is a very basic query for starting out. Once I get this working, I plan to make the event's query a bit more advanced. That's why I'm using this and not simply post_type => array( 'news', 'event' )
.
When the above runs, there are no posts. When I change 'event' to another post type, it works just fine. It's definitely something related to the event post type but I'm not sure what. Have any ideas off the top of your head?
Thanks for any assistance!
Hi @rossberenson thanks, glad it has helped
I'm not sure what EO is doing here with the queries,
how does EO work for a single query, i.e. how is that WP_Query ?
Best regards
Hi @birgire!
I was wondering that. When I do a normal query with post_type => array( 'event', 'news')
, both events and news do show.
WP_Query is modified a little bit by the plugin. It adds a few additional arguments. The arguments can be found here. I was thinking it might be because when event
is queried, it's ordered by the event date instead of post_date. My hunch was that was affecting combine queries. Whatever I seemed to do, I couldn't get events to show. Do you think my hunch is correct?
Thanks for the info
It looks like it's modifying the query through various filters e.g. here
https://github.com/stephenharris/Event-Organiser/blob/a48945b05ea90b5ef5c1ac79fbf247965f5a29fc/includes/event-organiser-archives.php#L236
This will probably need some digging to understand what's happening,
I will not be able to do that in the coming days, but hopefully in not so far future :-)
Ah, the filters. Thanks for taking a look! Whenever you have the time, I'm sure it'll benefit others too. Thanks again, much appreciated.