我正试图使用以下代码对我的自定义帖子使用多个自定义分类法进行筛选,但我的新代码一直是空的,即循环中没有帖子出现。
其工作原理如下:用户从表单中的三个不同下拉列表中选择自定义分类法的术语“fttype”、“ftperiod”和“ftduration”,并将其传递给以下代码:
我最初有这段代码(虽然没有分页),但我正在尝试实现的新代码无法使用WP 3.1内置的通过多个自定义分类进行过滤的功能(请参阅下面的新代码)。
有人知道我做错了什么吗?这件事已经有一段时间了。。。
谢谢
osu
OLD CODE
// Set todays date to check against the custom field StartEventDate
$todaysDate = date(\'Y/m/d\');
// Convert spaces in taxonomies and terms into hyphens so that search works correctly (uses slug)
$ft_t_ns = osu_convert_spaces($ft_t);
$ft_p_ns = osu_convert_spaces($ft_p);
$ft_d_ns = osu_convert_spaces($ft_d);
// Build query
// NOTE: AS OF WP 3.1, SEE V2 FOR HOW TO PASS AN ARRAY TO query_posts(). YOU PROBABLY WON\'T NEED
// QUERY MULTIPLE TAXONOMIES PLUGIN EITHER FOR V2\'S APPROACH OF PASSING AN ARRAY TO WP_Query() TO WORK.
// READ MORE ON \'MULTIPLE TAXONOMY HANDLING\' HERE:
// http://codex.wordpress.org/Function_Reference/query_posts#Taxonomy_Parameters
$ft_args = \'post_type=ftevent\';
$ft_args .= \'&fttype=\' . $ft_t_ns;
$ft_args .= \'&ftperiod=\' .$ft_p_ns;
$ft_args .= \'&ftduration=\' . $ft_d_ns;
$ft_args .= \'&posts_per_page=\' . $ft_ppp;
$ft_args .= \'&meta_key=StartEventDate&meta_compare=>=&meta_value=\' . $todaysDate;
$ft_args .= \'&orderby=meta_value&order=ASC&paged=\' . $paged;
// Create query
query_posts($ft_args);
NEW CODE
$ft_args = array(
\'post_type\' => \'ftevent\',
\'posts_per_page\' => 5,
\'paged\' => $paged,
\'orderby\' => \'meta_value\',
\'order\' => \'ASC\',
\'meta_query\' => array(
array(
\'key\' => \'StartEventDate\',
\'value\' => $todaysDate,
// Custom field type. Possible values are \'NUMERIC\', \'BINARY\', \'CHAR\', \'DATE\', \'DATETIME\', \'DECIMAL\',
// \'SIGNED\', \'TIME\', \'UNSIGNED\'. Default value is \'CHAR\'.
\'type\' => \'DATE\',
// Operator to test. Possible values are \'LIKE\', \'NOT LIKE\', \'IN\', \'NOT IN\', \'BETWEEN\', \'NOT BETWEEN\'.
// We choose \'BETWEEN\' because we need to know the date has not passed to show the event
\'compare\' => \'BETWEEN\'
)
),
\'tax_query\' => array(
\'relation\' => \'AND\',
array(
\'taxonomy\' => \'fttype\',
\'field\' => \'slug\',
\'terms\' => $ft_t_ns,
// Operator to test. Possible values are \'LIKE\', \'NOT LIKE\', \'IN\', \'NOT IN\', \'BETWEEN\', \'NOT BETWEEN\'.
// We choose \'IN\' because we need to make sure the term is in the current array of posts
\'operator\' => \'IN\',
),
array(
\'taxonomy\' => \'ftperiod\',
\'field\' => \'slug\',
\'terms\' => $ft_p_ns,
\'operator\' => \'IN\',
),
array(
\'taxonomy\' => \'ftduration\',
\'field\' => \'slug\',
\'terms\' => $ft_d_ns,
\'operator\' => \'IN\',
),
)
);
// Create query
query_posts($ft_args);