我用下面的代碼列出所有與特定的分類名稱和內容:動態分類項
$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