E、 g.我有这样的想法:
$continent = $_POST[\'continent\'];
if ($continent != 0) {
// get specific taxonomy e.g. with id=3 which is africa
$continent_query = array(
\'taxonomy\' => \'continent\',
\'field\' => \'term_id\',
\'terms\' => $continent
);
} else {
// how to build query array to search all terms?
// I DON"T KNOW THIS CODE!!!
$continent_query = array( ?????????????? );
}
我通过post表单发送大陆变量,它是一个整数。如果是“0”(选择框中的所有contintent),那么我需要构建
$continent_query 查询所有术语。如果是特定的,则查询,例如仅2或3等。
以下是查询:
$args = array(
\'post_type\' => array( \'post\' ),
\'posts_per_page\' => 10,
\'tax_query\' => array(
$continent_query,
)
);
$wp_query = new WP_Query( $args );
你知道如何为“0”做到这一点吗?
最合适的回答,由SO网友:gmazzap 整理而成
$continent_query = array(
\'taxonomy\' => \'continent\',
\'field\' => \'term_id\',
\'terms\' => 0 != $continent ? $continent : get_terms(\'continent\', array(\'fields\'=>\'ids\'))
);