我使用以下代码列出具有特定分类法名称的所有内容:
$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调用动态地放置"terms“名称,如下所示:
$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/>';
}但是,当然,语法是错误的。我该怎么做呢?谢谢!
发布于 2016-01-13 15:31:14
$CountryName = echo the_title();不是为变量赋值的正确方式。
在这种情况下,如果要使用外部变量,则必须执行$CountryName = get_the_title();。或者只是在查询中使用get_the_title()。
发布于 2016-01-13 15:22:07
那么$countryName实际上就是帖子的标题吗?如果是:$countryName = get_the_title();
https://stackoverflow.com/questions/34769903
复制相似问题