我已经按照Carbon Fields Association字段的文档进行了操作,但是当我尝试使用这些值时,我什么也没有得到。我已经在后端创建了该字段,一切似乎都很好地工作在那里,但是在前端,我使用了carbon_get_post_meta( $id, $name );,其中$id是get_the_ID(),$name是我的字段名related_products。有没有人能告诉我如何使用这个字段,或者告诉我任何可能有帮助的地方?谢谢
carbon_get_post_meta( $id, $name );
$id
get_the_ID()
$name
related_products
bxjv4tth1#
在关联字段中,值以以下格式获取。示例:
Array( [0] => Array ( [value] => post:post:11876 [type] => post [subtype] => post [id] => 11876 ) [1] => Array ( [value] => post:post:12101 [type] => post [subtype] => post [id] => 12101 ))
Array
(
[0] => Array
[value] => post:post:11876
[type] => post
[subtype] => post
[id] => 11876
)
[1] => Array
[value] => post:post:12101
[id] => 12101
字符串现在你有了数据,你可以获取它并相应地显示。这将从给定的数组中获取id。
$ids = wp_list_pluck( $related_products, 'id' );
型现在你可以使用这些id来获取帖子并根据需要显示。
$related_products_details = get_posts( array( 'post__in' => $ids, ) );
$related_products_details = get_posts( array(
'post__in' => $ids,
) );
型注:这只是一个概念,您需要根据自己的需求进行修改。
1条答案
按热度按时间bxjv4tth1#
在关联字段中,值以以下格式获取。示例:
字符串
现在你有了数据,你可以获取它并相应地显示。
这将从给定的数组中获取id。
型
现在你可以使用这些id来获取帖子并根据需要显示。
型
注:这只是一个概念,您需要根据自己的需求进行修改。