Forums Forums Search & Filter Pro Query vars and results order don't match

Viewing 10 posts - 1 through 10 (of 10 total)
  • Trevor
    #206932

    The sf_edit_query_args hook will ignore any post__in (did you use 2 underscores in yours?) argument you pass, but sorting should work.

    Can you post up the actual code you are using (inside code back ticks)?

    Anonymous
    #206964
    This reply has been marked as private.
    Trevor
    #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
    #207085

    I commented out the function that used the sf_edit_query_args hook. Then I added the query set to my existing modify_search_results_order function that’s using pre_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
    #207089

    I 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 to add_filter not add_action – should I be using that instead?

    Trevor
    #207116

    I do not know what might be causing that. The server logs should show you more detail. You could try what you suggest.

    Anonymous
    #207139

    I’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
    #207143

    I got the shortcode to show again – nevermind on that part. Still working with getting the post order correct. Will post again if I find any other clues. Thank you for your patience.

    Anonymous
    #207147

    Ok 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.

    Anonymous
    #207153

    I figured it out! These posts were stickies! I don’t even have the words – spent so much time on this. Wow. I removed the sticky status on these posts and then everything was fine. Please mark this as resolved.

Viewing 10 posts - 1 through 10 (of 10 total)