Forums › Forums › Search & Filter Pro › Include results in every search
- This topic has 4 replies, 2 voices, and was last updated 9 years, 4 months ago by Ross.
-
Anonymous(Private) June 23, 2015 at 7:24 am #20062
Hello… I don’t know if my brain is fried from working on this project for too long or what. I have a custom post type (“Charities”) using Advanced Custom Fields (ACF) and one of the fields is a checkbox for whether a Charity Organization is national (otherwise it’s just local).
Right now, a user can search by State (using a dropdown), but every state should include the national organizations (even if they’re not located in that State) as well as the local ones. I haven’t been able to accomplish this using the isNational checkbox custom field, so I tried to accomplish it using a taxonomy (applying the category “All Markets” to each national charity organization). However, I am unable to include the “All Markets” charity organizations in every search result. Is there a way to accomplish this?
I tried to add the “All Markets” category ID to the “Tags, Categories, & Taxonomies” tab (using “Include”), but that limits all search results to organizations within the “All Markets” category, which is not what I want. I simply want any organization in the “All Markets” category to show up in the search results, in case a user searches a State that contains no local charity organizations. That way the user understands there are still organizations that serve his or her area, even if they’re not based there.
Ross Moderator(Private) June 23, 2015 at 10:50 am #20083Hi Kevin
Anything added in the post meta tab is performed with an AND relationship, so if you add a field which matches
price
=200
– then only products worth 200 will show up – or if you setinstock
to1
– then you will only get items that are in stock.I see what you are trying to do – but this does not function in that way.
You could try to modify the search query yourself using
pre_get_posts
to achieve what you want – check here on correct usage with S&F:https://support.searchandfilter.com/forums/topic/filtering-by-meta/#post-12908
Thanks
Anonymous(Private) June 23, 2015 at 3:12 pm #20102Hi Ross,
Thanks very much for taking the time to reply. I had scoured the support forum very closely, so had already seen the code for modifying the query, but I also noticed that the modification in the example serves to further restrict the results (based on author).
I’m not sure how I would go about modifying the query to expand the number of returned results. I understand that is beyond the scope of your support, though, so I don’t expect you to spend time on it. Will 2.0 be able to accomplish what I am looking for?
Thanks!
Ross Moderator(Private) June 24, 2015 at 10:24 am #20167Hey Kevin,
v2 will be a step in the right direction (logic/code wise) but won’t have that specific functionality in.
What you are looking for is a kind of advanced query builder, so you can define the relationship of every element in the query (AND/OR) and how they work together.
WP only allows you to set this on Taxonomies and Post Meta – so twice you can define this, so anything to do with taxonomies in the query can be either AND or OR – but you can’t be granular with this.
The same with post meta – the updates I’m doing are a step in teh right direction, but the final solution is a way off (I’m thinking there actually needs to be some kind of drag and drop UI, where you can group fields together and other parts of the query, and setting AND/OR relationships anywhere you want – but this is pretty complex!)
Thanks
Ross Moderator(Private) June 24, 2015 at 10:25 am #20168PS, take a look here at the “relation” variable – https://codex.wordpress.org/Class_Reference/WP_Meta_Query
If you can modify that using pre_get_posts then you might be able to achieve what you want in this instance (provided you are not using other meta fields on your search form).
-
AuthorPosts