Support » Fixing WordPress » Storing multiple meta_query arrays before the query

  • Resolved SpankMarvin


    I’m having a senior moment with this, and think there must be a simple way to do this.

    I have a gallery that is accepting multiple $_GET values to filter content. This content is used in meta_query arrays to filter custom post data. This is simple enough when I place the arrays inside the meta_query array. Everything works as expected. However, I want to be able to have an author text search override a drop-down name select, meaning that I would love to house all of my separate meta_query arrays in a pre-defined variable, then just pop that into the wp_query object.

    the problem with just adding arrays to something like $filter[] is that the keys stop the query from executing properly. array_values() doesn’t help either.

    Can anyone help me think of an idea?

    Thank you in advance.


Viewing 1 replies (of 1 total)
  • Turns out the solution was for me to stop, sleep and look again at my code 🙂

    Basically, run through the GET paramaters passed from the form, and then add to an array like so:

    							$filters[] = array('key' => 'art_filtername', 'value' => $_GET['art_filtername_text'], 'compare' => 'LIKE' );
    						} else if($_GET['art_filtername']){
    							$filters[] = array('key' => 'art_filtername', 'value' => $_GET['art_filtername']);
    							$filters[] = array('key' => 'art_price_regular', 'value' => array($price[0], $price[1]), 'type'=>'numeric', 'compare' => 'BETWEEN' );

    and then call this array as the value of ‘meta_query’:

    'meta_query' => $filters

    This now works as expected.

Viewing 1 replies (of 1 total)
  • The topic ‘Storing multiple meta_query arrays before the query’ is closed to new replies.