Skip Navigation

[Resolved] Filter on custom field in many to many relationship not working

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

Problem:

Filter results by another post type fields.

Solution:

There isn't such a built-in feature within Views plugin, this is a wordpress limitaion:

https://toolset.com/forums/topic/filter-on-custom-field-in-many-to-many-relationship-not-working/#post-1092810

Relevant Documentation:

https://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters

This support ticket is created 6 years, 5 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
- 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/Hong_Kong (GMT+08:00)

This topic contains 3 replies, has 2 voices.

Last updated by annemariev 6 years, 5 months ago.

Assisted by: Luo Yang.

Author
Posts
#1092417
screencopy1.JPG
screencopy2.JPG
screencopy3.JPG
screencopy4.JPG
screencopy5.JPG

Hi,

Could you please help me with the following:

I have the following data structure:
- Post types: Activities + Locations
- Relationship: Location-Activity (Many-to-Many)

I am trying to create a view in which users can select Activities based on the following filters:
1. Activity Type (Taxonomy Activities)
2. Location (Relationship filter Location-Activity)
3. Location Type (Custom Field Locations)

When I create a new filter and select Location Type Toolset creates the following code:

<div class="form-group">
<label>[wpml-string context="wpv-views"]Locatie type[/wpml-string]</label>
[wpv-control-postmeta field="wpcf-locatie-type" url_param="wpv-wpcf-locatie-type"]
</div>

This field however doesn’t seem to have a relationship with the other filter fields or result (activities). After refreshing the page location types can be selected, but after selecting an options, no results are shown. Also when I select an activity type, the location types are not automatically updated.

Please advice.

Best regards, Annemarie

#1092798

just changed the order of the attached images

#1092810

Hello,

There isn't such a built-in feature within Views plugin, Views is using wordpress class WP_Query to query the posts, In your case, you are using view to querying the "Activities" posts, so you can only filter the result by the custom fields/taxonomies of post type "Activities", since there isn't "Location Type" field in the "Activities" post, so it is expected result:
after you select a "location types" options,no results are shown.

So when it is querying posts one post type "Activities", and filter the result by fields of anther post type "Locations", you can only filter the result by custom fields/taxonomies of post type "Activities".

It is a wordpress limitaion:
https://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters

#1092836

Thank you for your response. I'm afraid I will have to find another solution.