Forums › Forums › Search & Filter Pro › Searching based on multiple CPT
- This topic has 17 replies, 3 voices, and was last updated 4 years, 6 months ago by Ross.
-
Ross Moderator(Private) April 29, 2020 at 2:49 pm #241990
Hi Keith
I’ve had a quick look at this.
The issue is, a make or a model is only a numeric value in the post meta (the post ID), so any kind of sorting related to this post meta doesn’t really work, logically.
I’ve had a look through ACF forums for this sort of thing and they don’t provide a simple solution:
https://support.advancedcustomfields.com/forums/topic/orderby-post-object-title-not-post_id/However there is this one:
https://support.advancedcustomfields.com/forums/topic/ordering-by-custom-field-of-relationship-field-object/But again its very complicated.
Essentially, you need to get all the posts from the relationship field, order them alphabetically, store their IDs in the correct order, and then sort our results using that order – its would be rather complex and probably not very efficient (in terms of amount of processing taken to achieve that affect)
We do have a filter to allow custom ordre of results in this way – so if you want to go down that road I can share (its not listed in our docs yet because we had planned to change the name)
Thanks
Ross Moderator(Private) April 29, 2020 at 3:31 pm #242002Hi Keith
The filter is
sf_apply_filter_sort_post__in
$post__in = apply_filters('sf_apply_filter_sort_post__in', $this->query_args['post__in'], $this->query_args, $this->sfid);
Which takes an array of post IDs (the results S&F has found) and must return those posts.
You’ll then have to disable sorting and sort by
post__in
in the query (actually, you might be able to leave this set as “default” ordreing in your search form options), you can use thesf_edit_query_args
filter to do this.If you’re going to follow the link above exactly, the
JOIN
option might work for you anyway, but there’s two potential approaches for you to try.Thanks
-
AuthorPosts