【问题标题】:Wordpress custom post type: returning *all* values of a multiple select list fieldWordpress 自定义帖子类型:返回多选列表字段的 *all* 值
【发布时间】:2017-12-12 00:22:06
【问题描述】:

我在专用 php 模板(无 Pods 模板)中的 Wordpress 循环中回显来自自定义帖子类型(使用 Pods 创建)的所有自定义字段值。这适用于所有自定义字段,relationship / simple / multiple selection list 字段除外。仅回显/返回多个选定值中的第一个。

我在 php 模板中使用了这段代码:

while ( have_posts() ) : the_post();
  $title = get_the_title();
  $image = get_the_post_thumbnail();
  $location = get_post_meta(get_the_id(), 'location', true);
  $types = get_post_meta(get_the_id(), 'types', true);
  etc.

稍后我会重复所有这些价值观。我有问题的字段是types

当我回显$types 时,仅回显/返回该字段的第一个选定值。我认为它可能是一个数组,并尝试print_r($types) 进行检查,但这也只显示一个(第一个选择的)键/值对,没有数组。

字段选择类型为multiple-select,格式为checkboxes(如果有任何相关性)。

我可以做些什么来获取和显示该字段的所有选定值?

【问题讨论】:

    标签: php wordpress custom-post-type podscms


    【解决方案1】:

    https://developer.wordpress.org/reference/functions/get_post_meta/ 您设置为“true”的最后一个参数是告诉 WP 您是否只希望返回单个值。 尝试将其更改为“假”。然后应该返回一个值数组。

    【讨论】:

    • Pods 单独存储我们的多选值,因此可以使用 WP_Query 很好地查询它们:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-03-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-17
    • 2014-06-25
    • 1970-01-01
    相关资源
    最近更新 更多