我已使用下页中的方法创建了一个名为位置的分类法。
如何从名为 Location 的字段获取数据并返回其值。请帮忙!谢谢
最佳答案
根据上面 URL 中给出的教程,考虑为媒体部分注册分类名称“位置”。下面的代码将有助于从字段位置获取数据
$tax_terms = get_terms('location', array('hide_empty' => false));
foreach($tax_terms as $term)
{
$termcat = $term->term_id;
$term->name;
$post = get_posts(array(
'post_type' => 'attachment',
'tax_query' => array(
array(
'taxonomy' => 'location',
'field' => 'term_id',
'terms' => $termcat)
))
);
foreach ($post as $mypost)
{
echo $mypost->post_title . '<br/>';
echo $mypost->post_content . '<br/>';
echo $mypost->ID . '<br/><br/>';
echo $mypost->ID . '<img src="'.$mypost->guid.'" width="150" height="150" />';
}
}
关于wordpress - 如何获取 WordPress 附件分类数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30110263/