使用Wordpress,我正在尝试编写一个php脚本,给定一个帖子ID,返回所有相关的自定义标签(也称为自定义术语,即我可以用来元描述帖子的这些词,并且是类别 - 例如,在this page中,自定义术语是" passabile"和#34;惊悚")。
有没有办法做到这一点,可能是一些负责自定义标签修改的WP方法?
非常感谢
答案 0 :(得分:0)
使用get_post_meta()
功能。假设您的标记名为“custom_terms”,您可以这样做:
$terms = get_post_meta( $id, 'custom_terms' );
如果您已经在帖子上想要获取该信息,请执行以下操作:
$terms = get_post_meta( get_the_ID(), 'custom_terms' );
见这里:http://codex.wordpress.org/Function_Reference/get_post_meta
$terms
将是一个包含所有值的数组。
编辑:如果您严格谈论帖子的标签,可以try this:
$tags = get_the_tags();
这将返回一个标记对象数组,您可以通过它们循环访问它们。
答案 1 :(得分:0)
使用
<?php
$id = //post id
$taxonomy = //your custom texonomy name
get_the_term_list( $id, $taxonomy );
?>
的更多信息