[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().
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]?
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.
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