Skip Navigation

[Resolved] Parametric search: Filtering by parent type's field

This support ticket is created 8 years, 2 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.

Our next available supporter will start replying to tickets in about 2.31 hours from now. Thank you for your understanding.

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

Last updated by Minesh 8 years, 1 month ago.

Assisted by: Minesh.

Author
Posts
#367503

Hi!
I have a view with a parametric search for "evento-corso" post type
evento corso is child of crystal-nails-corsi

I'd like to filter by a field "livello" id="$crystal-nails-corsi"

I've tried this but it doesn't work

 [wpv-control field="livello"  id="$crystal-nails-corsi" url_param="livello" type="select" auto_fill_default="cerca" auto_fill="wpcf-livello" auto_fill_sort="asc"]

The result is no item found

At the same time in the Output template of this view I can see correctly

 Livello:[types field="livello" id="$crystal-nails-corsi"][/types]

Can you help me?

Thank you! Alba 🙂

#367980

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

As I understand you want to filter your post by specific parent custom field [types field="livello" id="$crystal-nails-corsi"][/types].

You can pass argument of your parent field to child view and filter the child view with views shortcode argument. :
For example:

[wpv-view name="Child view - listing training posts" child_of="[wpv-post-id]"]

More Info
=> https://toolset.com/documentation/user-guides/passing-arguments-to-views/
=> https://toolset.com/documentation/user-guides/using-a-child-view-in-a-taxonomy-view-layout/
=> https://toolset.com/documentation/user-guides/filtering-views-by-custom-fields/

This related tickets may help you:
https://toolset.com/forums/topic/how-filter-child-post-by-parent-field/
https://toolset.com/forums/topic/how-to-filter-childs-post-depending-on-a-parent-field-value/

If your issue still persist, please do not hesitate to get in touch with me with a test example about your current CPT setup.

#368361

Hi! 🙂
Can you write me the exat way to insert that shortcode in my code?

- This view is for evento-corso
- that is child of crystal-nails-corsi
- LIVELLO is a field of crystal-nails-corsi

[wpv-filter-controls]

[wpml-string context="wpv-views"]<label>Difficoltà:</label>[/wpml-string][wpv-control field="livello"  url_param="livello" type="select" auto_fill_default="cerca" auto_fill="LIVELLO" auto_fill_sort="asc"]

  
[wpv-filter-submit name="Cerca il tuo Corso" type="input"]  

[wpv-filter-reset reset_label="Azzera la ricerca" type="input"]
[/wpv-filter-controls]

Thank you so much!
Alba

#368599

Minesh
Supporter

Languages: English (English )

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

Sorry but I'm bit confuse here - could you please explain me what exactly you want to display and what are the filters you want to have - a dummy test case will be helpful to understand your requirement.

#369600

Ok i'll try to explain better 🙂

For example:

I have a custom post type "Events" that is child of "courses" and "locations"
courses+locations+date (the only field that belongs to Events) =events

I have a view with a parametric search that is applied to "Events"

I'd like to filter by the field "province" that belongs to "locations"

I don't know how to write in the search that "province" belongs to "locations"

i'd like to have as result the list of all the events for the selected province

Thanks!! 🙂
Alba

#369637

Minesh
Supporter

Languages: English (English )

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

You need to create parent/child views.

1)
- Create a view "Events-child"
- "Content Selection" section select CPT "Events"
- "Query Filter" section add:

Post relationship filter
Select posts that are a children of the Post set by parent View.

- Loop output section, add post link, for example:

[wpv-layout-start]
	[wpv-items-found]
	<!-- wpv-loop-start -->
		<wpv-loop>
          [wpv-post-link]
		</wpv-loop>
	<!-- wpv-loop-end -->
	[/wpv-items-found]
[wpv-layout-end]

- save your view

2)
- Create a view "locations-parent"
- "Content Selection" section select CPT "Location"
- "Filter" section add field "province", for example

[wpml-string context="wpv-views"]province:[/wpml-string] [wpv-control field="province" url_param="province" type="select" auto_fill_default="Please select" auto_fill="wpcf-province" auto_fill_sort="asc"]

- Loop output section, add child view "Events-child", for example:

[wpv-layout-start]
	[wpv-items-found]
	<!-- wpv-loop-start -->
	<ul class="wpv-loop js-wpv-loop">
		<wpv-loop>
			[wpv-view name="child-view-pr-events"]
		</wpv-loop>
	</ul>
	<!-- wpv-loop-end -->
	[/wpv-items-found]
	[wpv-no-items-found]
		<strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
	[/wpv-no-items-found]
[wpv-layout-end]

-save your view

3)
Add your parent view "locations-parent" to your page and you will have results you are looking for.

Please refer to the following links that may help you:
=> https://toolset.com/documentation/user-guides/using-a-child-view-in-a-taxonomy-view-layout/
=> https://toolset.com/documentation/user-guides/querying-and-displaying-child-posts/
=> https://toolset.com/documentation/user-guides/passing-arguments-to-views/

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