wordpress - 如何获取 WordPress 附件分类数据

标签 wordpress metadata attachment taxonomy

我已使用下页中的方法创建了一个名为位置的分类法。

http://code.tutsplus.com/articles/applying-categories-tags-and-custom-taxonomies-to-media-attachments--wp-32319

如何从名为 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/

相关文章:

Perl:Win32::OLE 和 Microsoft Outlook - 有效地遍历电子邮件附件

mysql - Wordpress 本地主机 OSX 安装 : Error establishing a database connection

php - 从 PHP 中的字符串输入中删除特定字符串

wordpress - 如何在 Dockerfile 中下载和解压

python - 诱变剂:如何在 mp3、flac 和 mp4 中检测和嵌入专辑封面

javascript - 在将文件发送到服务器之前如何删除它们?

wordpress - localhost padding,信号段错误

html - 元名称和元属性有什么区别?

c#:使用程序集(通过反射)作为(元)数据存储

java - 如何使用 JAVA Rest API 从 Rally 工作项下载附件?