我正在尝试在我的主题的 function.php 文件中创建以下函数,并通过我的 taxonomy.php 文件调用它
query_brands_geo('dealers', 'publish', '1', $taxtype, $geo, $brands);
所有变量都在 taxonomy.php 中设置。
如果我将它直接放在我的 taxonomy.php 文件中,则以下查询非常有效。为了使这项工作成为一项功能,我缺少什么?
作为一个函数,对于 2-6 重复的参数,我得到了这个错误语句:
警告:query_brands_geo() 缺少参数 2
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' );