简体   繁体   English

Wordpress 自定义帖子类型:返回多选列表字段的 *all* 值

[英]Wordpress custom post type: returning *all* values of a multiple select list field

I am echoing all the custom field values from a custom post type (created with Pods ) within the Wordpress loop in a dedicated php template (no Pods template).我在 Wordpress 循环中的专用 php 模板(无 Pods 模板)中回显来自自定义帖子类型(使用Pods创建)的所有自定义字段值。 This works for all custom fields except for a relationship / simple / multiple selection list field.这适用于除relationship / simple / multiple selection list字段之外的所有自定义字段。 There only the first one of the multiple selected values is echoed/returned.只有多个选定值中的第一个被回显/返回。

I am using this code in the php template:我在 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.

Later on I am echoing all these values.稍后我会回应所有这些价值观。 The field I have the problem with is types :我有问题的领域是types

When I echo $types , only the first selected value of that field is echoed/returned.当我 echo $types ,只回显/返回该字段的第一个选定值。 I thought it would probably be an array and tried print_r($types) to check that, but that also only displays one (the first selected) key/value pair, no array.我认为它可能是一个数组并尝试print_r($types)来检查它,但这也只显示一个(第一个选择的)键/值对,没有数组。

The field selection type is multiple-select , the format checkboxes , if that's of any relevance.字段选择类型是multiple-select ,格式checkboxes ,如果这有任何相关性。

Any ideas what I can do to get and display all selected values of that field?有什么想法可以获取和显示该字段的所有选定值吗?

See https://developer.wordpress.org/reference/functions/get_post_meta/ The last parameter which you have set to 'true' is to tell WP if you only want a single value returned.请参阅https://developer.wordpress.org/reference/functions/get_post_meta/您设置为“true”的最后一个参数是告诉 WP 是否只想返回单个值。 Try changing it to 'false'.尝试将其更改为“假”。 An array of the values should then be returned.然后应该返回一组值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM