Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not work when querying events and posts - Maybe event plugin issue? #27

Open
rossberenson opened this issue Oct 30, 2021 · 4 comments

Comments

@rossberenson
Copy link

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!

@rossberenson rossberenson changed the title Does not work when querying event and posts - Maybe event plugin issue? Does not work when querying events and posts - Maybe event plugin issue? Nov 1, 2021
@birgire
Copy link
Owner

birgire commented Nov 1, 2021

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

@rossberenson
Copy link
Author

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?

@birgire
Copy link
Owner

birgire commented Nov 3, 2021

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 :-)

@rossberenson
Copy link
Author

rossberenson commented Nov 3, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants