I am trying to set up a query filter to search for offices in a building. The offices are child posts, buildings are the parent.
I need to set up a parametric filter to search for office space (by size) from the child, and a via the parent post title as a text search. Is this possible?
I don't really understand how to use the attribute function if that is a possible way of doing if?
Hi, we could implement something like this but the text field for parent post title would need to be substituted with another input type. A select field, radio button group, checkbox group, etc. is fine, but a text field isn't possible here. Even if it were possible, it seems like it would introduce too many possibilities for error to be practical, in my opinion. Considering spelling errors, punctuation differences, abbreviations, etc, I don't think the search algorithm would be very effective like this.
Is there a specific reason you want to use a text input? Perhaps if I understand more about your request I can recommend another way to provide a parent filter that will work in our system and serve your users as well.
Hi, The specific reason is for the user to search a street or building name.
I do already have a field for location in the parent post that is a simple text field, but it doesn't work very well. For instance, there are 7 offices available in 3 buildings in 1 street called Margaret street. If I search 'Margaret' it only shows 4 results. If I search for 'Margaret Street' it returns only 2 results. It is possible I haven't configured it correctly, so I've included some screen shots.
Ideally, if possible I would like it to populate it dynamically, exactly like admin when you search for a parent post relationship, which works like a dream. Is this possible?
Thanks in advance for any help you can give me.
Yes, I can see how an autosuggest input would be useful here but unfortunately that is not an input type we offer in Views just yet. One suggestion I can make would be similar to the Real Estate reference site we have set up:
http://discover-wp.com/site-types/bootstrap-estate-layouts/
If you try out the demo, you can see that the State and City filters are set up to include only options with available results. In your case, you could use Street and Building instead, but the concept would be the same. This is about as close as I can get you to an autosuggest input right now. Let me know if I can help you integrate something like this. Otherwise you're a bit limited with a text input field, as you have already noticed, mostly because of the way WordPress search works.
One way to help extend the capability of searching custom fields is to add a plugin called Relevanssi. We have some more information about that here:
https://toolset.com/documentation/user-guides/searching-texts-custom-fields-views-relevanssi/
This can help you search using custom fields and a text search input, but it would only apply to custom fields in the post itself and not parent posts.
Thanks Christian. Unfortunately the state and city filter would not work, as they are all in the same city and all roads or buildings in one part of town.
I'll try Relevanssi but it would have to be the free version.
Just a thought, but how about adding a jquery-chosen to a select field. Is it possible to add a class to the select input? Like this example hidden link
Do you think that would work if I listed the parents?
Unfortunately the state and city filter would not work, as they are all in the same city and all roads or buildings in one part of town.
Just to be clear, I meant that you would have filters for Street Name and Building Name, not filters for City and State. When the user selects a street name in the first filter, the building options would update to include only buildings on the selected street. This was just an example to show you the functionality of filters that update to include only the available options. More info about that here:
https://toolset.com/documentation/user-guides/front-page-filters/advanced-settings-custom-search/
Just a thought, but how about adding a jquery-chosen to a select field. Is it possible to add a class to the select input?
That's a great idea, but Views isn't tested for compatibility with this plugin and I can't guarantee it will work. It also falls into the realm of custom integrations, so I can't offer much support for it. But I don't see any reason not to try it out. You can add a custom CSS class to a parent select field by adding the "class" attribute to the select field shortcode:
[wpv-control-post-ancestor type="select" default_label="Select a Project" ancestor_type="project" class="custom-class-name"]
You can find this shortcode by editing your View. It's in the Filter Controls panel. This and other shortcodes are documented here: https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-control-post-ancestor