I am trying to create the below function in my theme's function.php file and call it from my taxonomy.php file via
query_brands_geo('dealers', 'publish', '1', $taxtype, $geo, $brands);
all variables are set in taxonomy.php.
The below query works perfect if I put it directly in my taxonomy.php file. What am I missing to make this work as a function?
As a function I get this error statement for argument repeated for 2-6:
Warning: Missing argument 2 for query_brands_geo()
function query_brands_geo($posttype, $poststatus, $paidvalue, $taxtype, $geo, $brands) {
/* Custom Query for a brand/geo combination to display dealers with a certain brand and geography */
//Query only for brands/geography combo and paid dealers
$wp_query = new WP_Query();
$args = array(
'post_type' => '$posttype',
'post_status' => array($poststatus),
'orderby' => 'rand',
'posts_per_page' => 30,
'meta_query' => array(
array(
'key' => 'wpcf-paid',
'value' => array($paidvalue),
'compare' => 'IN',
)
),
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => $taxtype,
'field' => 'slug',
'terms' => $geo
),
array(
'taxonomy' => 'brands',
'field' => 'slug',
'terms' => $brands
)
)
);
$wp_query->query($args);
}
add_action( 'after_setup_theme', 'query_brands_geo' );