1

This is the code I am using:

$results = array(
                'post_type' => 'score',
                'tax_query' => array(
                    array(
                        'taxonomy' => 'competitions',
                        'field' => 'slug',
                        'terms' => $tax->slug,
                        'compare' => '='
                    )
                ),
                'meta_query' => array(
                    array(
                        'numberposts'   => -1,
                        'post_type' => 'score',
                        'meta_key'     => 'horse_name',
                        'meta_value'   => $horsename,
                        'compare' => 'LIKE'
                    )
                )
           );

// query
$the_query = new WP_Query($results);

The problem is I can't work out how to make a Boolean AND expression so that both the taxonomy and the custom field should match before returning a post.

Tomerikoo
  • 18,379
  • 16
  • 47
  • 61

1 Answers1

0

I revised your code. check below code.

$results = array(
    'post_type'        => 'score',
    'posts_per_page'   => -1,
    'tax_query'        => array(
        array(
            'taxonomy' => 'competitions',
            'field'    => 'slug',
            'terms'    => $tax->slug,
            'compare'  => '='
        )
    ),
    'meta_query' => array(
        array(
            'meta_key'   => 'horse_name',
            'meta_value' => $horsename,
            'compare'    => 'LIKE'
        )
    )
);
// query
$the_query = new WP_Query( $results );
Bhautik
  • 11,125
  • 3
  • 16
  • 38