0

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 1

2

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' );
     }
}
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.