我知道如何获取帖子的ACF字段,但我很难获得这些结果中的关系来返回ACF字段。
示例:
$args = array(
\'post_type\' => \'location\',
\'post__in\' => array(67)
);
$q = new WP_Query($args);
$locations = array();
while($q->have_posts()) : $q->the_post();
$p = get_post(); // gets the basic post details
$f = get_fields(); // gets the ACF details
$m = array_merge((array)$p, (array)$f); // merges all details into one array
array_push($locations, $m);
endwhile;
这表明Array
(
[0] => Array
(
[ID] => 67
[ACF_Field => This is a custom field/value.
...
[ACF_Relationship_Field] => Array
(
[0] => WP_Post Object
(
[ID] => 133
// there should be another [ACF_Fiel]/value here
...
)
)
)
)
因此,数组的第一级中包含ACF值,但您可以看到第二级中没有。我看着the ACF Reference 这有助于我达到这一点,但不幸的是,我还没有找到任何能与ACF字段相关的关系。