This is on the second page of a filter that I am making, on the first page the user is able to select check-boxes. The values of the check-boxes get passed to the second page by parameters in the URL:
filter-result/?mytaxonomy=myterm&mytaxonomy=myotherterm
How to form an array of this data to use in a (WP) query?
I'm able to display the data from the URL by doing this:
if( isset( $_GET['mytaxonomy'] ) ){
foreach( $_GET['mytaxonomy'] as $term ){
echo $term . '<br>';
}
}
I am also able to query posts (custompost-type):
$query = new WP_Query( array(
'post_type' => 'mycustomposttype',
'tax_query' => array(
array(
'taxonomy' => 'mytaxonomy',
'field' => 'slug',
'terms' => array( 'myterm', 'myotherterm' ),
'operator' => 'AND',
),
),
) );
I want to pass the data from $_GET['mytaxonomy'] to 'terms' => array( *inside here* ).
When I use print_r ($_GET['mytaxonomy']); the result is Array ( [0] => myterm ), All correct. I guess I just need to form the array to 'a', 'b' to work in the WP query. How can I achieve this?