Forums Forums Search & Filter Pro Custom Post Types Missing from Archive

Viewing 7 posts - 1 through 7 (of 7 total)
  • Anonymous
    #48942

    Sooooo,

    I’ve just setup a search archive (search.php), and have added it to my search parameters to ensure that custom post types are included using the following code:

    // Add Custom Post Types to archives
    
    	add_filter( 'pre_get_posts', function( \WP_Query $query ) {
    
    	    if ( $query->is_tag() || $query->is_category() || $query->is_author() || $query->is_page_template( 'search.php' ) && $query->is_main_query() ) {
    
    	    	$meta_query = array(
    	    		'relation' => 'OR',
    	    		array(
    					'key'     => 'radix_status',
    					'value'   => 'value1',
    					'compare' => '==',
    				),
    				array(
    					'key'     => 'radix_status',
    					'compare' => 'NOT EXISTS',
    				)
    			);
    
    			$query->set( 'post_type', array('post', 'news', 'work', 'events', 'nav_menu_item') );
    			$query->set( 'order', 'DESC' );
    			$query->set( 'meta_query', $meta_query );
    
    	    }
    
    	} );

    But I’ve clearly done something wrong in setting this up, because it’s not working as intended.

    I have two issues with it thus far:

    1. Custom Post Types aren’t being displayed. They’re listed in the counts, but not showing up in the actual page content.

    2. The title of the page refuses to change. I’ve tried the recommended code:

    // Edit Search Title 
    
    add_filter('wp_title','search_form_title');
    
    	function search_form_title($title){
    
    	 global $searchandfilter;
    
    	 if ( $searchandfilter->active_sfid() == 451)
    	 {
    	 return 'Search Results';
    	 }
    	 else
    	 {
    	 return $title;
    	 }
    
    	}

    But it still just says “Opinion” – somehow I’ve got it stuck on JUST that post type?!

    Any ideas what I’ve done wrong. I’ve been looking and looking but can’t quite twig.

    Anonymous
    #48943

    Apologies. Link to the search page: http://radix.org.uk/search/

    Trevor
    #48966

    I think Ross will need to cast his eyes over your code. I have assigned this to him to answer when he has a free minute.

    Anonymous
    #48969

    Thanks, Trevor!

    Anonymous
    #49092

    My code above seems to be causing issues. When removed the custom post types appear just fine! Will have to look into other ways of achieving what this code did for me.

    Trevor
    #49127

    Is this (sort of) resolved for now?

    Anonymous
    #49160

    It is. This seems to be a theme conflict rather than the plugin’s doing. I have it working on my test site, so I’d imagine it’s something to do with the templates/hierarchy loading the POSTS page, rather than the search page. Either way, I’ll figure it out 🙂

    Thanks for your help!

Viewing 7 posts - 1 through 7 (of 7 total)