I’m currently looking into a solution to make a search query based on a minimum number of results, also when not all search options match.

Ideal situation;

I have made a custom post type and added a couple of shoes with different colors and sizes. And I am querying with WP\_Query() for ‘blue shoes’ and ‘size 8’. When I do this query, I only get 3 blue-colored shoes in size 8. Now I want to add 7 more equal shoes in size 8 to get a total of 10 shoes.

How would I do this within Wordpress in combination with Advanced Custom Fields?

I have made a custom WP\_Query based on the WP\_query() method. And made an array to store all post-results based on the first query and if the length of that array is not equal to 10 it will do an additional query.

So far so good, but then I get duplicate results:

=> I get the 3 already found blue-colored shoes in size 8, and again in the second query all the size 8 shoes including the already found shoes (from the first query).

See my code below;

```
$shoe_array = array();

$args = array(
    'numberposts'   => -1,
    'post_type'     => 'my_shoes',
    'meta_query'    => array(   
        'relation'      => 'AND',           
        array(
            'key'       => 'size',
            'value'     => 8,
            'compare'   => 'LIKE'
        ),
        array(
            'key'       => 'color',
            'value'     => 'blue',
            'compare'   => 'LIKE'
        ),
    ),
    'orderby'           => 'date',
    'order'             => 'DESC'
);

$shoes = new WP_Query( $args );
$posts = $shoes->posts;

foreach($posts as $post) {

    array_push($shoe_array, $post->post_name);

}

if (count($shoe_array) > 9) {

    echo 'Result of found shoes: ';
    print_r($shoe_array);   

} else {

    $args = array(
        'numberposts'   => -1,
        'post_type'     => 'my_shoes',
        'meta_query'    => array(   
            'relation'      => 'AND',
            array(
                'key'       => 'size',
                'value'     => 8,
                'compare'   => 'LIKE'
            )
        ),
        'orderby'           => 'date',
        'order'             => 'DESC'
    );

    $extra_shoes = new WP_Query( $args );
    $posts = $extra_shoes->posts;

    foreach($posts as $post) {

        array_push($shoe_array, $post->post_name);

    }

    echo 'Result of found shoes: ';
    print_r($shoe_array);

}

```

Anyone know how to make the query 'smarter'?

Please feel free to ask me additional questions if needed. Thanks! :-)