php 如何使用Carbon Fields 3显示“关联”字段

zu0ti5jz  于 2024-01-05  发布在  PHP
关注(0)|答案(1)|浏览(190)

我已经按照Carbon Fields Association字段的文档进行了操作,但是当我尝试使用这些值时,我什么也没有得到。我已经在后端创建了该字段,一切似乎都很好地工作在那里,但是在前端,我使用了carbon_get_post_meta( $id, $name );,其中$idget_the_ID()$name是我的字段名related_products
有没有人能告诉我如何使用这个字段,或者告诉我任何可能有帮助的地方?
谢谢

bxjv4tth

bxjv4tth1#

在关联字段中,值以以下格式获取。示例:

  1. Array
  2. (
  3. [0] => Array
  4. (
  5. [value] => post:post:11876
  6. [type] => post
  7. [subtype] => post
  8. [id] => 11876
  9. )
  10. [1] => Array
  11. (
  12. [value] => post:post:12101
  13. [type] => post
  14. [subtype] => post
  15. [id] => 12101
  16. )
  17. )

字符串
现在你有了数据,你可以获取它并相应地显示。
这将从给定的数组中获取id。

  1. $ids = wp_list_pluck( $related_products, 'id' );


现在你可以使用这些id来获取帖子并根据需要显示。

  1. $related_products_details = get_posts( array(
  2. 'post__in' => $ids,
  3. ) );


注:这只是一个概念,您需要根据自己的需求进行修改。

展开查看全部

相关问题