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

  • You are going to need to add another section to the query to cover post types that do not have either of the fields.

    
    $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'
                        ),
                    ),
                    // custom fields do not exist
                    array(
                       'relation' => 'AND',
                        array (
                          'key'       => 'job_status',
                          'compare'   => 'NOT EXISTS'
                        ),
                        array (
                          'key'       => 'opportunity_status',
                          'compare'   => 'NOT EXISTS'
                        ),
      
                      )
                ) );