Support

Home Forums Event Espresso Premium EE4 search

EE4 search

Posted: August 26, 2017 at 12:00 am

Viewing 11 reply threads


solwebsolutions

August 26, 2017 at 12:00 am

Hi!
We’re using the default WordPress search widget, and our events aren’t getting pulled back in search results.
https://www.lafsn.org/event-calendar/

Try keywords yoga, spanish, duck, fire…nothing found.
Please advise…thank you!


Josh

  • Support Staff

August 26, 2017 at 11:21 am

You may need to add some code like this to your site:

http://www.remicorson.com/include-all-your-wordpress-custom-post-types-in-search/

You can add the above to a functions plugin or into your WordPress theme’s functions.php file.


solwebsolutions

August 26, 2017 at 12:45 pm

I’ve added this code to the bottom of the eduma functions.php file, and still no results:

function rc_add_cpts_to_search($query) {

// Check to verify it’s search page
if( is_search() ) {
// Get post types
$post_types = get_post_types(array(‘public’ => true, ‘exclude_from_search’ => false), ‘objects’);
$searchable_types = array();
// Add available post types
if( $post_types ) {
foreach( $post_types as $type) {
$searchable_types[] = $type->name;
}
}
$query->set( ‘post_type’, $searchable_types );
}
return $query;
}
add_action( ‘pre_get_posts’, ‘rc_add_cpts_to_search’ );


Josh

  • Support Staff

August 28, 2017 at 7:35 am

Can you check to see if there are any other functions that hook in to pre_get_posts, either from the theme or another plugin? There may be some code that’s resetting the search query. You can also follow these steps to rule out a plugin/theme conflict:

https://eventespresso.com/wiki/troubleshooting-checklist/


solwebsolutions

August 28, 2017 at 7:47 pm

Hi!
I’ve gone through the checklist and the only thing is we’re on GoDaddy.
Please advise…thank you!


Josh

  • Support Staff

August 28, 2017 at 8:53 pm

So the search still didn’t return event posts with all other plugins deactivated and with the default theme activated? Is the hosting plan on Godaddy managedWP? If so has caching been disabled?


solwebsolutions

August 29, 2017 at 12:39 am

Hi Josh!
Great point…I changed template to TwentySixteen, and search worked.
UGH…looks like it’s the Eduma template.
https://themeforest.net/item/education-wordpress-theme-education-wp/14058034

I tried this code in functions.php for the theme, but no luck:

function remove_g1_precontent_render() {
    if ( 'espresso_events' == get_post_type() ) {
        remove_action( 'g1_precontent', 'g1_precontent_render' );
    }
}
add_action( 'g1_precontent', 'remove_g1_precontent_render', 9 );

Anything I could ask the theme developers to focus on?
Thank you!


Tony

  • Support Staff

August 29, 2017 at 2:56 am

I have an older version of Eduma but it doesn’t have the above action within it so I’m not sure what the above is trying to do as I can’t see any of that code.

However I did take a look at the version of Eduma I have and it has a thim_pre_get_posts_filter function that sets searches to only use post types of ‘post’ and ‘page’ that are published:

if ( $query->is_search ) {
	if ( empty( $_REQUEST['post_type'] ) ) {
		$query->set( 'post_type', array( 'post', 'page' ) );
	}
	$query->set( 'post_status', array( 'publish' ) );
	wp_reset_query();
}

That’s the problem as EE events are posts with a post_type of ‘espresso_events’, they aren’t included in the above.

You can add something like this:

https://gist.github.com/Pebblo/d1780fee1ce28e98fcd5eed01241a8d9

To a Custom Functions Plugin on your site to include EE events and venues within the earch (remove ‘espresso_venues’ from the code if you don’t want to include Venues).

I don’t think it’s a good idea for the theme to specifically set the posts types it should search. That basically removes support for searching any custom post types without setting that post type in the code above again so you may want to create a ticket with Edmua for to fix this in the theme.

If the above does not fix the search it may be something different in a newer version, if you can send me a copy I’ll take a look and see whats changed.


solwebsolutions

August 29, 2017 at 8:07 pm

Hi Tony,

Are you saying I look in functions.php?

I’m not seeing your code in:
public_html/wp-content/themes/eduma/functions.php


Tony

  • Support Staff

August 30, 2017 at 1:37 am

I’m not sure what you mean, are you looking for my custom code within your theme? If so you’re not going to find it.

To fix your problem you need to create a custom functions plugin on your site by following the guide I linked to above:

https://eventespresso.com/wiki/create-site-specific-plugin-wordpress-site/

Then add the custom code I created to that plugin:

https://gist.github.com/Pebblo/d1780fee1ce28e98fcd5eed01241a8d9

That function adds the EE events and EE venues to the post types that your site will search when using the search function. It does that after your theme has ‘done its thing’ that is breaking the search so you don’t need to alter the theme itself.

If you want to take a look at the function that is causing the problem, on my version of Eduma it is within \eduma\inc\custom-functions.php around 2240. It’s the thim_pre_get_posts_filter function.


solwebsolutions

August 30, 2017 at 10:30 pm

Thank you!
This code worked…but even with the same permissions in it’s own plugin, it wouldn’t fire. So, I put it in the theme’s functions.php file for now:

function tw_add_ee_to_thim_pre_get_posts_filter( $query ) {
	if ( ! is_admin() && $query->is_main_query() ) {
		if ( $query->is_search ) {
			if ( empty( $_REQUEST['post_type'] ) ) {
				$query->set( 'post_type', array( 'post', 'page', 'espresso_events', 'espresso_venues' ) );
			}
			$query->set( 'post_status', array( 'publish' ) );
			wp_reset_query();
		}
	}
}
add_action( 'pre_get_posts', 'tw_add_ee_to_thim_pre_get_posts_filter', 1010 );

Thank you for the help!


Tony

  • Support Staff

August 31, 2017 at 2:28 am

Hmm strange, it works fine in a plugin for me.

Either way, I’m glad it’s working for you.

Viewing 11 reply threads

The support post ‘EE4 search’ 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