Skip Navigation

[Resolved] Create a custom search filter using a relationship

This support ticket is created 6 years, 4 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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 13 replies, has 4 voices.

Last updated by Nigel 5 years ago.

Assisted by: Nigel.

Author
Posts
#1081688

Tell us what you are trying to do?
I have two custom post types. The first is an expert and the second is an event. The event has a custom field: event date. The two post types are related in a many to many relationship. I would like to display all experts but add a search filter of events dates.

Is there any documentation that you are following?
Watched some tutorials and read the how to document.

Is there a similar example that we can see?

What is the link to your site?
hidden link

#1082804

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi there

The feature of filtering one type of post by fields of another type of post is not yet supported, but is the main feature that will be added in the next Views development cycle, starting soon.

In the meantime you can only filter something by its own properties, although you can get halfway there with M2M relationships by filtering based upon the relationship fields.

So if you have speakers appearing at events and manage this with an "appearances" relationship, you could store a date field for the appearance. It would then be possible to filter speakers according to those dates.

You should expect work on the following Views version which includes filtering by fields of related posts to be complete in a couple of months or so.

#1084032
screenshot-vanleer-experts.ussl.blog-2018.08.15-23-24-05.png
screenshot-vanleer-experts.ussl.blog-2018.08.15-23-23-19.png
screenshot-vanleer-experts.ussl.blog-2018.08.15-23-20-49.png

I followed your suggestion and added an appearance date field to the relationship. I added this field to the view filter but the result is still empty. What am I doing wrong?

#1084551

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi there

It looks like the problem is that your Query Filter for the date is comparing it as a string, and it should be compared as a NUMBER or UNSIGNED.

Can you edit the filter and change the compare type and test again?

#1087332

Nigel, I did as you suggested and even tried other data types with no luck 🙁

#1087398

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Could I take a look at your site to check the set up myself?

I will mark your next reply as private so that I can get log-in credentials from you—you may want to create a temporary admin user for me to use that you can later delete. And be sure to have a current backup of your site, even though I don't intend to make any changes.

Where is the View displayed?

#1088298

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Do you have some additional layer of protection? The wp-admin page gives me a 404 error.

I'll mark your next reply as private again in case you have something else I need to know.

#1088449

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

I was struggling somewhat looking at your site because of the Hebrew, trying and failing to get it to work.

So I went back to basics and tried to set it up on my local test site—only to find it doesn't appear to be working as expected.

The View which includes a filter by a relationship field always returns no results.

That's not what I was expecting, and I'm consulting with colleagues to verify if this is a bug and if it is expected to be working at all.

Once I've clarified that I'll get back to you.

#1089308

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

So, it seems there has been a misunderstanding between the developers and supporters about what is currently possible.

Specifically, you cannot filter posts by anything other than its own fields or taxonomies (which is how WP_Query works).

I mistakenly understood that the one exception was that it was possible to filter posts in a M2M relationship by the relationship fields (which are stored on an intermediate post type), but this, too, is something for which support is going to be added in the next Views dev cycle, which is about to commence.

Then it will be possible to filter by fields of related posts directly or by the relationship fields, but in the meantime it is not possible.

Sorry for leading you to think using the relationship fields was one way to achieve that now.

#1093810

Any update on this issue?

#1094776

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Sorry, no, this feature will be added in the next Views development cycle which is just beginning, but development of this (and other features in this cycle) and testing could take up to a couple of months.

#1191988

Hello,

"The feature of filtering one type of post by fields of another type of post is not yet supported, but is the main feature that will be added in the next Views development cycle, starting soon." Nigel

Is there anything new about this?

Regards,
Mansario

#1392837

Has there been any updates to these additions to views? In particular the filtering if related posts own fields ?

#1392989

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

No, sorry, it got displaced by other activity.

I recommend anyone that needs support for filtering by fields of related posts (including intermediate posts in M2M relationships) submit a support request at https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/.

That way the product manager will be aware of demand when deciding development priorities.