Skip Navigation

[Resolved] Filtering & Display Options for Posts with Repeatable Field Groups

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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 6 replies, has 2 voices.

Last updated by Don 3 years, 6 months ago.

Assisted by: Christian Cox.

Author
Posts
#2082399

Don

Tell us what you are trying to do?

I have been reading up on this in the docs and support tickets, but want to make sure i pick the correct setup from the getgo, based on what IS, and is NOT, possible with repeatable field groups for a post type.

1) For my example we will focus on a rentals website, with a post type of "rentals", wtih all content coming from users via a front end form.
2) A user posting a property can either post a listing describing a SINGLE property, ie via single custom fields for things like price, number of rooms, number of bathrooms and date available OR a post with a "floorplan" where multiple variations can be entered for each of these things, which would require a repeating field group.
3) It is important that the SEARCH/FILTERING of posts uses one search filter (ie a filter for price should filter posts regardless of whether was entered for a post describing just one property for for a price value within a repeating field group.
2) Posts in this post type will have custom fields for various things as single fields like location fields, description etc that are the same regardless of whether the post describes just one place with single fields or uses a repeating field group. These fields must also be used as filters in a view.

4) I am not sure if having "single" custom fields when is only about one place AND having repeating field group which include the SAME custom fields is even possible.... or if i have to use different and unique fields in the repeating field group even if is "about" the exact same thing (for example number of bedrroms). If I cannot use the same custom fields in a repeating field group, then that basically means i cannot search both with same filter, ie would basically have to filter TWICE, which for user on front end would be confusing and all in all ineffective.

5) Am not clear on how flexible we can display field values from a repeating field group. In my example, if a user creates a post and in the repeating field group creates 4 entries, each with different values for price, number of rooms, bathrooms and availability, in a single post template am I able to display the RANGE of these values somehow? for example under the title show "Bathrooms: 1-5" and Rent: $500-$950"? I know i can display the results in a table but wasnt clear on how easy it is to access and display repeating field values, and ideally with ranges like described....

6) IF repeating field group fields cannot be identical(ie the exact same field) to singular custom fields (like number of bedrooms), and be filtered together with one search filter in a view, then i will basically HAVE to all have all data for the post, regardless of whether it will have multiple values for a field or not, as a repeating field group so everything CAN be filtered via one filter. But I want to make sure that filtering post results with repeatable field groups is just as effective, and that we can filter multiple fields, easily enough in a vew just like with standard single field custom fields.....

#2083529

Hello, I'll try to provide some general feedback here and if we need to split off individual tickets for more detailed discussion I can handle that for you.

4) I am not sure if having "single" custom fields when is only about one place AND having repeating field group which include the SAME custom fields is even possible.... or if i have to use different and unique fields in the repeating field group even if is "about" the exact same thing (for example number of bedrroms).
It is actually not possible to use the same fields in a repeatable field group (RFG) as the fields in its parent post type. When you create fields in an RFG, the slugs for those fields must be different from corresponding fields in its parent post, even if they represent the same concept.

5) Am not clear on how flexible we can display field values from a repeating field group...for example under the title show...Rent: $500-$950"?
I can't think of a single block or shortcode you could use to display a range of custom field values from an RFG like this. One way to solve this problem with existing features is to use the legacy View editor to create a View of RFGs related to the current post, sorted by price field as a number in ascending order. In the unformatted loop of that View, you can use the wpv-item shortcodes to display only the first result and the last result (lowest and highest priced RFGs), and insert Types field shortcodes in each wpv-item set to display the price value from each of those results. Example of this scenario in the loop editor of such a View:

[wpv-layout-start]
	[wpv-items-found]
<!-- wpv-loop-start -->
	<wpv-loop>
		[wpv-item index=1]
		 Rent: $[types field="rfg-price"][/types] -
		[wpv-item index=last]
		$[types field="rfg-price"][/types]
	</wpv-loop>
	<!-- wpv-loop-end -->
	[/wpv-items-found]
	[wpv-no-items-found]
		<strong>[wpml-string context="wpv-views"][/wpml-string]</strong>
	[/wpv-no-items-found]
[wpv-layout-end]

That's the best way I can think of to display a range of custom field values using built-in Views and Types features. Otherwise a custom code approach with a custom shortcode might be required. I can help you set up something like I've described in the legacy Views editor if you're not familiar with the shortcode-based method of creating Views. It's a bit different from the Blocks-based Views editor approach and it's less intuitive if you're more familiar with drag-and-drop page builder systems like the Block Editor. I can split off a separate ticket where we can discuss in more detail if necessary.

...But I want to make sure that filtering post results with repeatable field groups is just as effective, and that we can filter multiple fields, easily enough in a vew just like with standard single field custom fields.....
You can filter upon custom fields in an RFG just as easily and with the same level of functionality as filtering upon custom fields in the parent post type. The limitations to be considered in a custom search View of the RFG are not related to the custom field filters, though...they are related to all the other types of filters. A View filtering by an RFG's custom fields cannot also filter by the parent post's custom fields, nor can it filter by the parent post's taxonomy terms or its established post relationships. Since it is not possible to apply taxonomies or post relationships directly to an RFG, that becomes a considerable limitation. The types of filters you can use in a custom search of RFGs is much more limited than a View of the parent post type. Hope this helps clarify what is and is not possible. If you'd like to explore in more detail what is or is not possible, we can set up a sandbox at our discover-wp.com site and create a similar scenario where we can collaborate.

#2083539

Don

thanks for the quick and thorough answer! To clarify, this means in a view that filtering "standard toolset custom fields" for a post type and filtering "repeating field group custom fields" for the same post type are mutually exclusive? So if I want to filter a post type at all i HAVE to commit from the get-go to either having all custom fields that I intend to be filterable as either ONLY custom fields OR only as a custom field within a repeating field group? IF that is the case then, as organized and cohesive as repeating field groups look they wont be a practical solution for me since rules out using other "must be filterable" standard toolset custom fields.... crumb. but i am sure the reasoning behind it is the daunting task of making the different fields play nice together as filters, so no grudges there lol.

Well... not as organized or elegant of a solution but, while i have you on the horn, what about a "creative" workaround with the standard singular custom fields, where it gives the choice between ONE value or multiple? Ie is NOT a part of a repeating field GROUP, but the singular field DOES save multiple values? THAT could perhaps allow me to have my cake and eat it too, ie all fields are standard custom fields and can be filtered AND I can have multiple values.... will be a challenge matching/creating a connection between the multiple values for one field up with the corresponding multiple values for the other "relevant" fields during post creation and single post display but maybe, just maybe, it could work?

#2083613

To clarify, this means in a view that filtering "standard toolset custom fields" for a post type and filtering "repeating field group custom fields" for the same post type are mutually exclusive?
Filtering by the custom fields in a repeatable field group and filtering by the custom fields in its parent post type are mutually exclusive in custom search Views. Your understanding is basically correct there. A repeatable field group is actually a separate custom post type from its parent post. Each row of an RFG is technically implemented as one post in that custom post type, and each of those RFG instances is related to its parent post in a one-to-many post relationship. That relationship is not exposed as a typical relationship in Toolset > Relationships, it is established behind the scenes, so to speak, in a way that is not obvious from wp-admin. However, the functionality of these relationships is basically the same as any other O2M relationship you create.

THAT could perhaps allow me to have my cake and eat it too, ie all fields are standard custom fields and can be filtered AND I can have multiple values.
I believe you are asking if it would be possible to implement each custom field in the parent post type as a field that allows multiple values, to circumvent the need for a repeatable field group containing these fields. It's possible to set things up like this, but most likely it would present some major challenges. You might find it difficult to manage and display these field values with no real programmatic connection between each "group" or instance of the custom field iterations. You can use Views to loop over RFG instances/rows, but you cannot use Views to loop over each set of custom field values. This makes it very difficult to display information from one specific instance of virtually unconnected fields. We do offer a shortcode that allows you to loop over instances of a single custom field that allows multiple values: wpv-for-each. However, this shortcode does not offer easy ways to find and display corresponding custom field values from the same "instance". Like if you loop over the instances of one custom field "abc", it's simple to display the value of 'abc' from row 1, then from row 2, then from row 3, etc. but it is quite difficult within that loop to also display custom field "xyz" from row 1, row 2 and row 3 in a logical connected way. In all likelihood, this is a deal breaker, but you're welcome to try it out and see what kinds of problems you run into.

#2083631

Don

thanks for the confirmation on mutual exclusivity and the behind the scenes explanation!

and thanks for the added info on fields that can contain multiple values.... this wpv for each shortcode sounds interesting, and promising..... i had sort of envisioned simply displaying the multiple values of "connected" fields next to each other in a grid format to hopefully give a semblance of connection/logical flow between the individual values. sure, things will get wacky if a user doesnt enter the same number of values for each "connected" field, and values will be misaligned, but this hiccup, if this idea would work at all, is a heck of a lot better than the dilemma of having to "pick" between standard custom fields or field groups!

#2083723

had sort of envisioned simply displaying the multiple values of "connected" fields next to each other in a grid format to hopefully give a semblance of connection/logical flow between the individual values
That's exactly what I mean when I say it's difficult to display these repeating values in a logical connected way with wpv-for-each. It allows you to display the custom fields grouped by field, like

Price: $100, $200, $300 
Square Feet: 100, 200, 300 
Bedrooms: 1, 2, 3 
Bathrooms: 1, 2, 3 

...but not grouped into columns as a grid, like:

Price | Square Feet | Bedrooms | Bathrooms
$100  | 100         | 1        | 1
$200  | 200         | 2        | 3
$300  | 300         | 3        | 3

That is not really possible with wpv-for-each, and would require custom programming.

#2084487

Don

My issue is resolved now. Thank you!