Skip Navigation

[Resolved] Using cusotm fields of repeatable field group as filter

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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Karachi (GMT+05:00)

This topic contains 9 replies, has 2 voices.

Last updated by alexanderW-6 1 year, 7 months ago.

Assisted by: Waqar.

Author
Posts
#2435679

Hi there,

I created a Custom Post Type "Event", that uses RFG for Multiplee Dates but further has a Select-Field to choose from Locations.
The view with the RFG-CPTs works fine, when i structure it with the Date-Fields and I can also output the Select-Field-Value but I can't use any of the Group-Fields to Filter.

Is this something that doesn't work... in all Issues-Topics I get the feeling, it should be work.

Thanks and kind regards, Alex

#2435873

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Alex,

Thank you for contacting us and I'd be happy to assist.

In view's search, filtering works only for the custom fields which are directly attached to the post type that is being shown by the view.

Technically, fields inside a repeatable field group are saved with a separate and hidden custom post type, which is why they can't be used for filtering the results of the parent post type.

To make this work, you can remove the date type field from the repeatable field group and add it directly to the field group attached to the "Event" post type.

And to store multiple dates with an event, you can set that individual field to be repeatable by enabling the option "Allow multiple instances of this field".

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar

#2435943

Hi Waqar,

thanks for your fast reply...

The custom fields I'm talking about are directly fields of the rfg and not the parent post and the view is also a view, that query the rfg (cpts) not the parent post. that's why I'm asking.

A repeatable date-field in a cpt "event" would not help me to have a date-sorted list view of these events... because i can only loop 1 event with different dates. therefore i need the rfg, right? if there is another workaround... i'm looking for this problem for many years now an think know all the concerning doc-post here 🙂

#2436429

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thanks for writing back.

If the view is also for the RFG post type, then yes, you should be able to filter by its date type custom field.

Can you please share temporary admin login details, along with the link to a page where this view can be seen? I'll be in a better position to guide you with the next steps, after understanding the setup and the requirement.

Note: Your next reply will be private and making a complete backup copy is recommended before sharing the access details.

#2436643

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thank you for sharing the access details.

I tried to log in to the website's admin area, but, it keeps showing the incorrect password message.

Can you please check the username and password again?

Note: I'm setting your next reply as private

#2439579

Hi Waqar,

I'm sorry! Please try it again with the above login. It now should work.

Thank you!!

#2440129

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

The admin access details worked, thank you.

As the select type field "Toolset Select Test Tax" doesn't have any predefined options and you're populating them programmatically, you'll need to manually specify the option titles and values when adding the filter for it in the view.
( while adding the search filter, make sure to select the option to enter options manually )

For example, in this case, the code for this search field will change from:


<div class="form-group">
	<label for="wpv-wpcf-toolset-select-test-tax">[wpml-string context="wpv-views"]Toolset Select Test Tax[/wpml-string]</label>
	[wpv-control-postmeta field="wpcf-toolset-select-test-tax" url_param="wpv-wpcf-toolset-select-test-tax"]
</div>

To:


<div class="form-group">
	<label for="wpv-wpcf-toolset-select-test-tax">[wpml-string context="wpv-views"]Toolset Select Test Tax[/wpml-string]</label>
	[wpv-control-postmeta type="select" field="wpcf-toolset-select-test-tax" source="custom" url_param="wpv-wpcf-toolset-select-test-tax" values=",4,5,6" display_values="-select-,test-tax-1,test-tax-2,test-tax-3"]
</div>

Note: The '4,5,6' are the term IDs of the "toolset-test-taxs" taxonomy terms and 'test-tax-1,test-tax-2,test-tax-3' are their titles.

You can read more about the accepted attributes for the "wpv-control-postmeta" shortcode at:
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-control-postmeta

You'll see that the search field for this select field is working on your example page now.

#2440817

Hey Waqar,

thank you, now it is working, but am I right, that in this case it is not possible to add dynamically new taxonomies to the filter, when a uses just adds one?

#2441005

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

You can make the list dynamic, by registering a custom shortcode, that can get all the terms from a taxonomy, and then as needed, either return the comma-separated list of their IDs or titles.

For example:


add_shortcode('custom_taxonomy_items_list', 'custom_taxonomy_items_list_func');
function custom_taxonomy_items_list_func($atts) {
	$return = $atts['return'];
	$taxonomy = $atts['taxonomy'];
	$output = array();

	$terms = get_terms( array(
		'taxonomy' => $taxonomy,
		'hide_empty' => false,
	) );

	foreach( $terms as $term ) {
		if($return == 'title') {
			$output[] = $term->name;
		}
		elseif ($return == 'ID') {
			$output[] = $term->term_id;
		}
	};
	return implode(',', $output);
}

The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through the active theme's "functions.php" file.

Note: Please also add "custom_taxonomy_items_list" in the "Third-party shortcode arguments" section, at WP Admin -> Toolset -> Settings -> Front-end Content.

This new shortcode accepts two attributes:
1. taxonomy: the slug of the taxonomy to get the terms from
2. return: can be 'ID' or 'title'

Example usage:


// get the comma-separated list of titles from the 'toolset-test-tax' taxonomy
[custom_taxonomy_items_list taxonomy="toolset-test-tax" return="title"]

// get the comma-separated list of IDs from the 'toolset-test-tax' taxonomy
[custom_taxonomy_items_list taxonomy="toolset-test-tax" return="ID"]

And, these shortcodes can then be used in the select field's shortcode in the view, like this:


[wpv-control-postmeta type="select" field="wpcf-toolset-select-test-tax" source="custom" url_param="wpv-wpcf-toolset-select-test-tax" values=",[custom_taxonomy_items_list taxonomy='toolset-test-tax' return='ID']" display_values="-selectzzz-,[custom_taxonomy_items_list taxonomy='toolset-test-tax' return='title']"]

This way, the static list of options, would become dynamic too.

Note: The custom code examples from our forum are shared to get you started in the right direction. You're welcome to adjust them as needed and for more personalized customization assistance, you can consider hiring a professional from our list of recommended contractors:
https://toolset.com/contractors/

#2441033

My issue is resolved now. Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.