![](/img/trans.png)
[英]How to get all custom field values for specific field for custom post type WordPress
[英]Wordpress custom post type: returning *all* values of a multiple select list field
我在 Wordpress 循環中的專用 php 模板(無 Pods 模板)中回顯來自自定義帖子類型(使用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
:
當我 echo $types
,只回顯/返回該字段的第一個選定值。 我認為它可能是一個數組並嘗試print_r($types)
來檢查它,但這也只顯示一個(第一個選擇的)鍵/值對,沒有數組。
字段選擇類型是multiple-select
,格式checkboxes
,如果這有任何相關性。
有什么想法可以獲取和顯示該字段的所有選定值嗎?
請參閱https://developer.wordpress.org/reference/functions/get_post_meta/您設置為“true”的最后一個參數是告訴 WP 是否只想返回單個值。 嘗試將其更改為“假”。 然后應該返回一組值。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.