Forums › Forums › Search & Filter Pro › Query vars and results order don't match
Tagged: post__in, pre_get_posts, query-vars, search results, sf_edit_query_args
- This topic has 10 replies, 2 voices, and was last updated 6 years, 3 months ago by
Anonymous.
-
Trevor(Private) April 1, 2019 at 2:00 pm #207055
If you are using the Custom display results method, did you try adding our filter to the pre_get_posts? Like this:
function pre_get_posts_function($query) { //this would be a pre_get_posts you already have in place somewhere //then set <code>search_filter_id</code> $query->set("search_filter_id", 123); } add_action( 'pre_get_posts', array($this, 'pre_get_posts_function') );
Anonymous(Private) April 1, 2019 at 3:19 pm #207085I commented out the function that used the
sf_edit_query_args
hook. Then I added the query set to my existingmodify_search_results_order
function that’s usingpre_get_posts
after all the query args I already set. For some reason it caused a fatal error regarding memory size. I thought maybe it was the syntax, so I changed it to$query->query_vars['search_filter_id'] = 493580;
and that seemed to cause endless looping with constant undefined index errors.Am I applying it correctly?
On my WP admin settings, I have the “Display Results” tab set where the method is “As an archive” and the template options are using a custom template, search.php. No slug set and no ajax.
Thanks.
Anonymous(Private) April 1, 2019 at 3:25 pm #207089I changed my Display Results tab settings where the method is “custom”, added in the url to my search results which is the WP default http://my-url/search, and I still get a fatal memory error.
The only difference is I noticed my
pre_get_posts
function is hooked toadd_filter
notadd_action
– should I be using that instead?Anonymous(Private) April 1, 2019 at 7:23 pm #207139I’ve undid the settings where I had “custom” set in my “Display Results” tab. So it’s back on archive and set to search.php how I originally had it. My PHP code is back to how I had it as well, minus any S&F hook customizations. However, now the shortcode on search.php is no longer showing the form. When I var dump it, it’s an empty string. Why would the form disappear on the search.php template after changing the “Display Results” settings to “custom” and then back to “archive”? I tried making a new form to see if that was the issue, and the shortcode still no longer outputs the form. 🙁
Anonymous(Private) April 1, 2019 at 8:28 pm #207147Ok so I found the issue – or at least what’s really happening. It’s not the orderby or any query args that I set.
The query for S&F and WP are the same at this point. I even commented out any other
pre_get_posts
filters I may have had elsewhere in my theme. What happens is for some reason, there are these 5 posts that get put on the top regardless of the search term/order/whatever. So I tried using the WP search with a keyword that had 7 results. I got the same 7 results with the S&F search in the order I wanted, however 5 unrelated posts were on top of them.If I change the search term, use the sorting field to change the order, the results change like they’re supposed to, with the exception of those 5 persistent posts on top. It’s the strangest thing – why would that happen?
I looked up the post IDs for these 5, and they are included in the
post__in
arg from S&F. I’m not finding any common link between them – they’re different post types. Different categories. I checked the post meta on one to see if there was custom meta from my end, nothing out of the ordinary.The results count is correct too, so if there are 7 results,
$wp_query->found_posts
will be 7. But what displays are those 7, plus those 5 results I can’t seem to get rid of. It’s really baffling. -
AuthorPosts