Skip Navigation

[Resolved] how to output view based upon "wpv-found-count" value

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 3 replies, has 2 voices.

Last updated by Minesh 9 months, 3 weeks ago.

Assisted by: Minesh.

Author
Posts
#2685848

Hello.
One of the custom fields in my custom post type uses a repeating field to display 3 items (single field, image, single field).

In the display template, I have added a view. How do I make the output display a different number of columns based upon the number "wpv-found-count" returns? i.e. if there is only 1 item returned, then display it in 1 column, 2 items in 2 columns, etc ...

Do I need to have multiple views for each quantity of results returned? or is there a way to dynamically set the number of columns the view-loop returns?

thx

G

#2685894

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

The first thing I would like to know is - Do you have repeating field or repeating field group?

Can you please share screenshot of your custom field group page?

And can you explain why you want to do such check - I mean, do you want that if only two fields have value then it should only display two columns?

In addition to that - Could you please send me debug information that will help us to investigate your issue.
=> https://toolset.com/faq/provide-debug-information-faster-support/

#2686045
Screen Shot 2024-03-01 at 2.43.38 PM.png

Hey Minesh ... thx for replying ...

OK ... so I can't just set the grid at three columns because a majority of the database entries will only have 1 of the repeating field groups ... a bunch have 3 and two of them have only 2

it seems like overkill to have 3 separate views on the page. Is it possible to use the same view multiple times on a page but have the output grid count be different each time I use it?

I guess what I am in need of help with is how can I determine the number of columns to set in the view's output grid column count to be equal to that number
so if there are 3 entries in a repeating field group then it will output three columns or if there is 1 entry then it will output 1 column.

thx

UPDATE:

ok ... so I have added the following to my functions.php file in my child theme.

(I have registered the short code and the function)

now this worked for me on a past client's website .. however ... I do not have access to that code any more and I dont' know how to access this new shortcode in a view.

now I am not sure if this will work for my CURRENT situation as i dont remember if the "GET_THE_ID() is for ... do I hard code that? or is that the ID of the post the view is inside of?

this will get me a number that I can use to determine the view output grid column setting (I assume) ... but again, can I set a different column count for the same view on the same page?

/* --------------------------------------------------------------------------------------------------------------------------------- */

// START get_repeating_field_group_count
// This function will determine the number of items in a repeating field group e.g. 'Product Colorway'
// so that different output may be generated based upon the number of itmes matched.
function get_repeating_field_group_count( $atts ) {
$a = shortcode_atts( array(
'id' => get_the_ID(),
'type' => 'three-view',
), $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', 'get_repeating_field_group_count' );
// STOP get_repeating_field_groups_count

/* --------------------------------------------------------------------------------------------------------------------------------- */

#2686235

Minesh
Supporter

Languages: English (English )

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

Unfortunately, there isn't such kind of built-in feature within Toolset Blocks plugin to set the number of grid columns for view's loop output dynamically.

#2686333

ok ... that is not optimal, but I can figure out a work around.

Thank you for your help