I am trying to create a relationship between two post types... In wordpress back-end I see the one-to-many relationship is working, but if I try and get a count of child post's it is returning zero, I can also not find the _wpcf_belongs_ record anywhere in the database which is normally there...
Hello. Thank you for contacting the Toolset support.
The forum link you shared as a reference is too old and was using the legacy relationship.
To count the number of child posts there are two ways, either you should go with views to display the count or use the post-relationship API method: toolset_get_related_posts()
For example:
global $post;
$child_posts = toolset_get_related_posts(
$post->ID, // the parent post
'relationship-slug', // replace the relationship slug
'parent', // no need to change
999, // the maximum number of results
0, // the offset
array(), // additional query arguments
'post_id', // return format
'child', // role to return
'',
'ASC'
);
$count = count($child_posts);
Thank you for the advise. Trying it now :).
Is this query resource intensive, I want to add it in a view to grab the total number's but if it pulls each post with it's meta info I can think if my list is 20 items and each item has 200 relationship items, it's going to get quite insane?