Problem:
I am moving a site over from using CMB2 to take advantage of the upcoming relationships API.
It contains repeating fields but using CMB2, they are just stored as a serialized array in post meta.
From reading the documentation, it seems Toolset stores them within a hidden CPT, and all I can see is tutorials for accessing them by using a View/GUI.
I wasn't intending to use Views for this project. Do you have documentation for how to access them with API Functions?
Solution:
There isn't exact document for the Repeating Fields Groups API, but it is using child post type to store the Repeating Fields Groups , so you can use function toolset_get_related_posts() to get the child posts, then display custom field of each child post, for example:
1) Create a Repeating Fields Groups "my-fields-group" in post type "my-cpt", add some custom field into the field group
2) In the your theme file single.php, add below codes:
$child_posts = toolset_get_related_posts( get_the_ID(), //Post to query by. 'my-fields-group', //Slug of the relationship to query by 'parent', //Name of the element role to query by. 100, //Maximum number of returned results 0, //Result offset array(),//Additional query arguments 'post_id', //Determines return type 'child' // which posts from the relationship should be returned ); var_dump($child_posts);
As you can see the last parameter is "child", it will be able to query the child posts of current post.
Relevant Documentation:
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
- | 9:00 – 13:00 | 9:00 – 13:00 | 9:00 – 13:00 | 9:00 – 13:00 | 9:00 – 13:00 | - |
- | 14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | - |
Supporter timezone: Asia/Hong_Kong (GMT+08:00)
Ce sujet contient 3 réponses, a 2 voix.
Dernière mise à jour par Il y a 6 années et 9 mois.
Assisté par: Luo Yang.