I’m using the dropdown categories function in a search form. When I use option “ALL” it does not show any results and I’d expect to show all the posts from all the categories. What am I missing?
Below is my query:
if ( isset($_GET['cat']) && isset($_GET['manufacturer']) ) {
$tax_query = array( 'relation' => 'AND' );
array_push($tax_query,
array(
'taxonomy' => 'manufacturers',
'field' => 'id',
'terms' => $_GET['manufacturer']
),
array(
'taxonomy' => 'category',
'field' => 'id',
'terms' => $_GET['cat']
)
);
}
$query_args = array(
'post_type' => 'yacht',
'meta_or_tax' => true,
'tax_query' => $tax_query,
'posts_per_page' => -1,
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'yachts_loa_length_round',
'value' => array($_GET['min_length'], $_GET['max_length']),
'compare' => 'BETWEEN',
'type' => 'NUMERIC',
),
array(
'key' => 'yachts_price',
'value' => array($_GET['min_price'], $_GET['max_price']),
'compare' => 'BETWEEN',
'type' => 'NUMERIC',
),
array(
'key' => 'yachts_year',
'value' => array($_GET['min_year'], $_GET['max_year']),
'compare' => 'BETWEEN',
'type' => 'NUMERIC',
)
)
);
$yacht_query = new WP_Query( $query_args );
and my php functions:
$args = array(
'orderby' => 'menu_order',
'show_option_all' => pll__('All '),
'order' => 'ASC',
'hide_empty' => 0,
'class' => 'form-select',
'taxonomy' => 'category',
'value_field' => 'term_id'
);
wp_dropdown_categories( $args ); ?>
$args = array(
'orderby' => 'menu_order',
'show_option_all' => pll__('All'),
'order' => 'ASC',
'hide_empty' => 0,
'name' => 'manufacturer',
'class' => 'form-select',
'taxonomy' => 'manufacturers',
'value_field' => 'term_id'
);
wp_dropdown_categories( $args ); ?>
Managed to solve it using this with help from @Milo on wordpress.stackexchange.com