Skip Navigation

[Resolved] Front-end search for repeating group field

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

Problem: I would like to search for posts using the value of a custom field in a repeating field group (RFG) assigned to that post.

Solution: This feature is not currently available, but there are some ways to get around it. You can create a custom search View of the RFG instead and filter by the custom field. You must add the search field manually, since the GUI does not allow it. Then in the Loop editor you can display information about the parent post using the "item" shortcode reference:

[wpv-post-link item="@truck-rfg.parent"]<br />
This support ticket is created 6 years, 3 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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

Last updated by Christian Cox 4 years, 7 months ago.

Assisted by: Christian Cox.

Author
Posts
#1090205

Hi! I have a custom post type name "Trucks" with custom fields and repeating group name "Truck", on the Truck group there is a "Truck #" field.

Is there a way to index and search the truck# on the frontend/views filter?

#1090293

To some degree, yes, but searching and filtering by RFG fields is somewhat limited right now. Here's what you can do:
1. Add a Query Filter to a View of RFGs to filter by this Truck Number custom field. Change the setting so the filter responds to a URL parameter like "wpv-wpcf-truck-number". Replace truck-number with the slug of your Truck Number custom field.
2. In the Search and Pagination settings, insert a new filter by pasting this code in the filter controls code (do not click "Add Filter", it won't let you add it this way):

<div class="form-group">
	<label>[wpml-string context="wpv-views"]Truck Number[/wpml-string]</label>
	[wpv-control-postmeta field="wpcf-truck-number" type="textfield" url_param="wpv-wpcf-truck-number"]
</div>

Replace truck-number with the slug of your Truck Number custom field.

If you cannot see the Search and Pagination settings, scroll to the top right corner and click "Screen Options". You can enable the panel here.

#1090324
Screenshot_18.jpg
Screenshot_17.jpg
Screenshot_16.jpg

I already tried what you suggest but when entering a Truck # the results is "No items found".
I've attached some screenshots.

#1090363

I can't see from the screenshot, but my guess is that this View is not set up to show the RFG, but you have chosen the parent post type in the Content Selection area instead. Is that correct? I was describing an approach that will filter a View of the Repeating Field Group, not the parent post type.

#1090366

Yes, the view is for post type with RFG, Is there a way to filter it?

#1090420

Not directly, no. What you can do is create a View of the Repeating Field Group, filtered by the custom field. Then in the Loop Output area, you can use shortcode attributes to display information about the parent post, like the post link. Here's an example of how that shortcode attribute looks:

[wpv-post-link item="@truck-rfg.parent"]<br />

Replace truck-rfg with the slug of the repeating field group. You can find the slug by editing the custom field group that contains the RFG.

This approach works well if there is only one matching RFG per parent post. If there are multiple RFGs in the same parent post that have asset numbers matching the filter, you can end up with repeating results in the View. There is a more complicated way around this, if it's something you want to explore. I can provide some assistance.

#1091003

All right! I'm hoping that this function will be available soon. Thanks!

#1586109

Has this function been added since this ticket was raised?

#1586743

It is still not possible to filter a View of some CPT by the fields in one of its Repeatable Field Groups, if that is what you are referring to. It is still necessary to create a View of the RFG, filtered by the custom field. Then output the parent post information in the View's loop using the "item" attribute in any shortcodes, like shown here:

[wpv-post-link item="@truck-rfg.parent"]<br />