Skip Navigation

[Resolved] Count number of entries in repeating field group return 0

This thread is resolved. Here is a description of the problem and solution.

Problem:
Count number of entries in repeating field group return 0

Solution:
To get total count based on repeating field group items, you will require to use the post relationship API function toolset_get_related_posts().

You can find proposed solution in this case with the following reply:
=> https://toolset.com/forums/topic/count-number-of-entries-in-repeating-field-return-0/#post-2067453

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

This support ticket is created 3 years, 6 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 stephaneL-3 3 years, 6 months ago.

Assisted by: Minesh.

Author
Posts
#2067367

Tell us what you are trying to do?
Count number of entries in repeating field

Is there any documentation that you are following?
https://toolset.com/forums/topic/count-number-of-entries-in-repeating-field-doesnt-work-if-there-are-no-entries/

Is there a similar example that we can see?
same thread (https://toolset.com/forums/topic/count-number-of-entries-in-repeating-field-doesnt-work-if-there-are-no-entries/)

What is the link to your site?
hidden link

I don' tunderstand why it will not return the right count number, perhaps being on an elementor page?
I tried to add it to the nested view of the repeating field, but no matter what the result is always 0??
The right field slug is used, I have a CPT Show, with a repeating group for the dates, used the shortcode function as outlined int he ticket refered to, but still return 0 ?

Also while on this, I have a list of dte then, and each date are confirmed with a check box, or not, if not checked. If I get this count to work and I use the slug of the Checkbox field (confirmed) will it count only the repeating groups where confirmed is [yes]?

thank you for your time

#2067401

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

That is really strange. Can you please tell me where you added the code that counts the number of repeating field entries and where exactly you want to display it.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2067411

Minesh
Supporter

Languages: English (English )

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

I do not see the option to access plugins/themes menu. Can you please grant me full admin rights.

As well as, can you please clarify, what custom field you want to count or you want to count the repeating field group entries?

#2067419

Hi again,

Sorry about the right, you shoul dhave access all area now.

The CPT group is: [Shows - Dates]
As for the Custom field, I used the date field: shwd-date

But happy to use any if it helps (Although the date is the one with shwd-type that will be filled for sure.

thanks
s

#2067453

Minesh
Supporter

Languages: English (English )

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

Instead of using the shortcode: [count_instances field="wpcf-shwd-date"]

I replaced the above shortcode with: [showDt-count] on your elementor's template within shortcode widget;
=> hidden link

I've adjusted and moved the code that counts the child post to "Custom Code" section offered by Toolset within the "Toolset Custom Code" snippet:
=> hidden link

add_shortcode('showDt-count', 'showDt_count_func');
function showDt_count_func($atts) {
  global $post;
   
  $child_posts = toolset_get_related_posts($post->ID,'shw-dates-grp','parent',999,0,array(),'post_id','child');
  return count($child_posts);  
}

I can see now it shows the correct count:
=> hidden link

#2067463

My issue is resolved now. Thank you!