【问题标题】:Wordpress: custom meta tag listingWordpress:自定义元标记列表
【发布时间】:2014-12-20 22:58:40
【问题描述】:

使用 Wordpress,我正在尝试编写一个 php 脚本,该脚本在给定某个帖子 ID 的情况下,返回所有相关的自定义标签(也称为自定义术语,即我可以用来元描述帖子并且属于类别的这些词-独立。例如,在this page 中,自定义术语是“passabile”和“thriller”)。

有没有办法做到这一点,可能是一些处理自定义标签修订的 WP 方法?

非常感谢

【问题讨论】:

    标签: php mysql wordpress


    【解决方案1】:

    使用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();
    

    这会返回一个标签对象数组,您可以通过循环访问它们。

    【讨论】:

    • 感谢您的回答...我得到的只是将 custom_terms 变量留空,是这样的: ["_edit_last"]=> array(1) { [0]=> string(1) " 1" } ["_edit_lock"]=> array(1) { [0]=> string(12) "1414253683:1" } } 我们说的是同一个术语吗?
    • 我们可能不是,但您的帖子并不清楚。这些是帖子的元数据吗?它们是标签吗?
    【解决方案2】:

    使用

    <?php 
    $id = //post id
    $taxonomy = //your custom texonomy name
    get_the_term_list( $id, $taxonomy ); 
    ?> 
    

    更多关于get_the_term_list的信息

    【讨论】:

    • 好电话 - 我仍然不确定 OP 是否正在寻找术语、标签、元数据等,并且忘记了他可能在谈论分类术语
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-02-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-11
    相关资源
    最近更新 更多