I am using a plugin called Event Organiser, and it seems that it will only append its custom properties to the post object for all other instances of the WordPress loop except the search. Is there a way to access the search loop only and inject these properties into each WP_Post instance in the results?
1 Answer
The custom properties you refer to are dates which a stored in a custom table, and which are joined onto the query for events. At this point in time, when querying events, this table is only joined when only the 'event' post type is being queried.
That is, you can search for events - but the dates are only pulled in if you are searching only for events. The following snippet will ensure all front-end ("main") searches are for events only - which may or not may not be the desired behaviour, but you can of course target specific queries or simply set the post type to 'event' when you create your WP_Query object.
add_action( 'pre_get_posts', 'wpse172161_set_search_post_type' ); function wpse172161_set_search_post_type( $query ){ if( !is_admin() && $query->is_main_query() ){ $query->set( 'post_type', 'event' ); } } -
$query->is_main_queryproperty does not exist in the WP_Query object btw. At least not in the search query.cj5– cj52014-12-15 17:16:16 +00:00Commented Dec 15, 2014 at 17:16 - It's a class method: github.com/WordPress/WordPress/blob/4.0/wp-includes/…Stephen Harris– Stephen Harris2014-12-26 23:24:41 +00:00Commented Dec 26, 2014 at 23:24