Skip Navigation

[Resolved] Toolset relationship fields arent being created

This support ticket is created 5 years, 5 months ago. There's a good chance that you are reading advice that it now obsolete.

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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 5 replies, has 2 voices.

Last updated by Minesh 5 years, 5 months ago.

Assisted by: Minesh.

Author
Posts
#1267263

hey Guys,

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...

Can you please assist?

I followed the guide here https://toolset.com/forums/topic/count-child-post/ to get it working, but still no success 🙂

#1267455

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

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);

More info:
=> https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts

#1269139

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?

#1269143

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - rather I comment on this I would suggest you to check with your code that will be the better option.

#1269183

Awesome it looks good.
Can you please advise me, is there a way to get the total number of children, for the children of the children?

Meaning: Post -> Post Child -> Child Post Child
I want to get the 2nd level's children if possible without creating loops in loops?

#1269191

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - there is no option as you need to get the child ID so you need to loop through.