Hello.
In my dataset I have a number of repeater groups, i.e. product colors, product shapes, etc ...
it is important that I am able to get the number of items in those groups so that I can tweak the display of the content-template appropriately.
Currently, I am using this function that was posted in response to another developer's question:
function func_get_repeating_field_group_count( $atts ) {
$a = shortcode_atts( array(
'id' => get_the_ID(),
'type' => 'product-colorway',
), $atts );
if ( (!empty($a['id'])) && (!empty($a['type'])) )
{
$section_ids = toolset_get_related_posts(
$a['id'],
$a['type'],
'parent',
1000,
0,
array(),
'post_id',
'child'
);
return count($section_ids);
}
}
add_shortcode( 'get_rfg_count', 'func_get_repeating_field_group_count' );
and then I trigger it by utilizing the new shortcode like this (to show content if the count is ≥ 4):
( ( '[get_rfg_count]' gte '4' ) )
my question is this: how do I modify this function so that I can use it on different fields, instead of the hard-coded "product-colorway" as I have it shown above?
again ... I would like to use a conditional block that will look at the COUNT() of a particular repeater and
if it has a COUNT() between 0 and 4 show VIEW A
if it has a COUNT() ≥ 4 then show VIEW B
thx,
Gordon
Hello,
You can use above shortcode for another post type relationship, for example:
[get_rfg_count type="my-relationship-B"]
Please replace my-relationship-B with your other post type relationship slugs.
Excellent.... that was exactly what I needed to know.
My issue is resolved now. Thank you!