我用下面的代码列出所有与特定的分类名称和内容:动态分类项
$myposts = get_posts(array(
'showposts' => -3,
'post_type' => 'post',
'tax_query' => array(
array(
'taxonomy' => 'country',
'field' => 'slug',
'terms' => array('Egypt'))
))
);
foreach ($myposts as $mypost) {
echo $mypost->post_title . '<br/>';
}
我要动态地把“条件”的名字,基于PHP的调用,喜欢的事这:
$CountryName = echo the_title();
$myposts = get_posts(array(
'showposts' => -3,
'post_type' => 'post',
'tax_query' => array(
array(
'taxonomy' => 'country',
'field' => 'slug',
'terms' => array($CountryName))
))
);
foreach ($myposts as $mypost) {
echo $mypost->post_title . '<br/>';
}
但是,当然,语法是错误的。我该怎么做?谢谢!
你在'$ CountryName'中有什么?它来自哪里? – Sumit