Support

Home Forums Event Espresso Premium Add Events to Search Results

Add Events to Search Results

Posted: June 27, 2017 at 1:22 pm

Viewing 1 reply thread


asse2014

June 27, 2017 at 1:22 pm

Does Event Espresso have a name for its custom post? Currently I am using the snippet below to add my custom posts to the results and would like to be able to include my Events.

/**

* This function adds custom posts to search results

*/

add_filter( ‘pre_get_posts’, ‘tgm_io_cpt_search’ );
/**
* This function modifies the main WordPress query to include an array of
* post types instead of the default ‘post’ post type.
*
* @param object $query The original query.
* @return object $query The amended query.
*/
function tgm_io_cpt_search( $query ) {

if ( $query->is_search ) {
$query->set( ‘post_type’, array( ‘encounters_news’, ‘encounters_jobs’ ) );
}

return $query;

}

Or is there another function that will add Events to the WP Search Results?


Josh

  • Support Staff

June 27, 2017 at 2:08 pm

That function should do it, and you can add espresso_events to the array. You might want to add post back into the array to make sure regular WP posts are included in the search too.

Viewing 1 reply thread

The support post ‘Add Events to Search Results’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso