简体   繁体   中英

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). This works for all custom fields except for a relationship / simple / multiple selection list field. There only the first one of the multiple selected values is echoed/returned.

I am using this code in the php template:

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 :

When I echo $types , only the first selected value of that field is echoed/returned. 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.

The field selection type is multiple-select , the format checkboxes , if that's of any relevance.

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. Try changing it to 'false'. An array of the values should then be returned.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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