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?
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.
I already tried what you suggest but when entering a Truck # the results is "No items found".
I've attached some screenshots.
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.
Yes, the view is for post type with RFG, Is there a way to filter it?
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.
All right! I'm hoping that this function will be available soon. Thanks!
Has this function been added since this ticket was raised?
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 />