[Resolved] Search results menu issue

Home Forums Support Search results menu issue

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1346865
    Mike

    When I use the navigation search. The results page is ok, but the menu is just the magnifying glass and no menu items, so i can’t go anywhere. What might be happening here?
    Thanks

    #1347159
    David
    Staff
    Customer Support

    Hi there,

    can you try disabling plugins to see if there is a conflict ?

    #1347227
    Mike

    Hi David. Had tried that – no conflict. But I put the site on a MAMP and disabled everything. Turns out it was one function in my child theme. You don’t need to answer this, but I’m baffled.

    This works OK

    add_filter( 'pre_get_posts', 'custom_post_type_search' );
    function custom_post_type_search( $query ) {
         if ($query->is_search) {
              $query->set('post_type', array( 'post', 'drlc_online', 'drlc_libraries', 'event'));
         }
         return $query;
    }

    But this breaks the menu:

    function rc_add_cpts_to_search($query) {
    	if( is_search() ) {
    		$post_types = get_post_types(array('public' => true, 'exclude_from_search' => false), 'objects');
    		$searchable_types = array();
    		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' );

    Any idea why? As I say, not your job to answer at all, just chancing the ask 🙂
    Mike

    #1347502
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Instead of this:

    if( is_search() ) {

    Try this:

    if ( $query->is_search() && $query->is_main_query() ) {

    #1347783
    Mike

    Thanks Tom.

    #1348544
    Tom
    Lead Developer
    Lead Developer
Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.