我遵循了 Carbon Fields Association 字段的文檔,但是當我嘗試使用這些值時,我什么也沒得到。我在后端創建了該字段,在那里一切似乎都運行良好,但在前端我使用carbon_get_post_meta( $id, $name );where $idisget_the_ID()和$nameis my field name related_products。誰能告訴我如何利用這個領域,或者指出任何可能有幫助的地方?
1 回答

倚天杖
TA貢獻1828條經驗 獲得超3個贊
在關聯字段中,按以下格式獲取值。例子:
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
)
)
現在你有了數據,你可以獲取它并相應地顯示出來。例子。
這將從給定的數組中獲取 id。
$ids = wp_list_pluck( $related_products, 'id' );
現在您可以使用這些 ID 來獲取帖子并根據需要顯示。
$related_products_details = get_posts( array(
'include' => $ids,
) );
注意:這只是一個概念。您需要根據您的要求修改它。
- 1 回答
- 0 關注
- 199 瀏覽
添加回答
舉報
0/150
提交
取消