我試圖從轉發器欄位內的帖子物件中獲取標題等。
$classes = get_field('classes'); //repeater field containing a sub field named "class" (post object).
<?php foreach($classes as $class) : ?>
<?php
echo $class; //returns post objects as arrays.
echo $class['title']; //returns nothing.
echo $class['post_title']; //returns nothing.
?>
<?php endforeach; ?>
回傳的內容:
[class] => WP_Post Object
(
[ID] => 57
[post_author] => 1
[post_date] => 2021-12-07 23:55:28
[post_date_gmt] => 2021-12-07 23:55:28
[post_content] => fffdfdf
[post_title] => testa
[post_excerpt] => dfdsgdsgf
etc.....
)
那么我如何獲得帖子標題等?
uj5u.com熱心網友回復:
根據 ACF 檔案,這是回圈遍歷中繼器欄位并加載子欄位值的方式:ACF | 中繼器
// Check rows exists.
if( have_rows('classes') ):
// Loop through rows.
while( have_rows('classes') ) : the_row();
// Load sub field value.
$product = get_sub_field('class');
// Access product info.
$product_id = $product->get_id();
$product_name = $product->get_name();
// End loop.
endwhile;
// No value.
else :
// Do something...
endif;
訪問產品資訊的方法串列。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/381052.html
