你知道为什么我的函数print\\r$arr有很多元素,但在print\\r$stack时只保留cat和dog吗?我需要在函数外部使用$arr,
function pre_selected_results() {
$args = array(...)
$the_query = new WP_Query($args);
$arr = array("Dog","Cat");
while ($the_query->have_posts()) :
$the_query->the_post();
$args = array(...)
$results = wp_get_post_terms(get_the_ID(),\'type\',$args);
foreach ($results as $result){
$arr[] = $result;
}
endwhile;
print_r ($arr);
return $arr;
};//End of pre_get_results function
$stack = pre_selected_results();
print_r ($stack);
非常感谢!
编辑:my$args以防有帮助:对于quey:
$args[\'tax_query\'] = array(
\'relation\' => \'OR\',
array(
\'taxonomy\' => \'category\',
\'terms\' => $_GET[\'category\'],
\'field\' => \'slug\',
),
array(
\'taxonomy\' => \'genres\',
\'terms\' => $_GET[\'genre\'],
\'field\' => \'slug\',
),
array(
\'taxonomy\' => \'types\',
\'terms\' => $_GET[\'type\'],
\'field\' => \'slug\',
),
);
对于wp\\u get\\u post\\u术语:
$args = array(\'orderby\' => \'name\', \'order\' => \'ASC\', \'fields\' => \'slugs\');
再次感谢