Support

Account

Home Forums ACF PRO add post type to search results and filter by meta value Reply To: add post type to search results and filter by meta value

  • Here you go – I had to comment the meta query in order to have the default search returning any results?

       function themeprefix_include_custom_post_types_in_search_results( $query ) {
            
            if ( $query->is_main_query() && $query->is_search() && ! is_admin() ) {
                
                $query->set( 'post_type', array( 'post', 'case', 'client', 'event', 'job', 'opportunity', 'partner', 'team' ) );
                /*
                $query->set( 'meta_query', array (
                    'relation' => 'OR',
                    array (
                        'relation' => 'AND',
                        array (
                          'key'       => 'job_status',
                          'compare'   => 'EXISTS'
                        ),
                        array(
                            'key'     => 'job_status',
                            'value'   => '1',
                            'compare' => '=',
                            'type'    => 'NUMERIC'
                        ),
                    ),
                    array (
                        'relation' => 'AND',
                        array (
                          'key'       => 'opportunity_status',
                          'compare'   => 'EXISTS'
                        ),
                        array(
                            'key'     => 'opportunity_status',
                            'value'   => '1',
                            'compare' => '=',
                            'type'    => 'NUMERIC'
                        ),
                    )
                ) );
                */
            }
        }
        add_action( 'pre_get_posts', 'themeprefix_include_custom_post_types_in_search_results' );