Forums › Forums › Search & Filter Pro › Ignoring Sticky Posts in filters?
Tagged: sticky posts
- This topic has 7 replies, 2 voices, and was last updated 10 years ago by
Anonymous.
-
Anonymous(Private) April 13, 2015 at 11:42 pm #15021
Hi Ross,
I have a filter working well except that at the top of any filtered results, it retains the sticky posts – how can I tell S&P Pro to ignore the sticky posts and just return results that match the selected filters?
I am using the “sticky” feature to keep certain posts at the top on other pages, if it’s absolutely necessary I can change to using a category (‘featured’) but that would mean re-writing a lot of existing queries and templates, etc., and I really like using the sticky function…it works great everywhere else but is causing me headaches with search filtering.
Any suggestions?
****UPDATED*****
Dang, I just saw someone else’s topic on this subject from January…..same need, using the WP sticky_posts, not a meta field……any idea when the update that includes an option to ignore sticky posts on the ‘Posts’ tab of S&P Pro will be released?
Ross Moderator(Private) April 14, 2015 at 12:00 am #15022Hey Trisha
I’m hoping to include it in the next 2.0 release out in roughly the next month…
How are you displaying your results?
If you are using the archive method, you could modify the search by using
pre_get_posts
and I think from there you might be able to change this sticky option..!? Haven’t tried it but here is the way to hook in to S&Fpre_get_posts
:https://support.searchandfilter.com/forums/topic/filtering-by-meta/#post-12908
In future modifying
pre_get_posts
will likely not be supported anyway which is why I don’t generally recommend it, but by the time that happens the sticky posts feature should be implemented anyway.Thanks
Anonymous(Private) April 14, 2015 at 2:43 am #15023Hi Ross,
I actually am already using pre_get_posts in order to limit the search results to only one type of post, and I tried adding the ignore_sticky_posts there, but it doesn’t work.
// Limit searches to only Deals function searchfilter($query) { if ($query->is_search && !is_admin() ) { $query->set('post_type',array('deal')); $query->set('ignore_sticky_posts',true); } return $query; } add_filter('pre_get_posts','searchfilter');
I’m doing this because the initial search results come from a standard WP searchform so it’s before the filters are displayed for use….without this the stock WP search function was searching through all content and including standard Post content in the results…..so I found this snippet of code and modified it to limit my search results to just the custom post type I want – it works fine, just not ignoring the sticky posts…..I tried using ‘1’ instead of ‘true’ (both with and without the single-quote-marks) and that didn’t work either.
Ross Moderator(Private) April 14, 2015 at 7:43 am #15034Hi Trisha
You should give the code I linked a try (notice the priority on
pre_get_posts
) 😉Also,
$query->is_search
will return true even when its not a search form, you should also use theis_valid_form
functionThanks
Anonymous(Private) April 14, 2015 at 11:37 pm #15076Well I did try that code and did not have the results I need……I think what I’m trying to do is perhaps just not possible, although I have a feeling what I need is a combination of what I’m using and that code you referred me to. Not being a coder, I’m at a loss to know if this can be done or how.
SO that snippet works correctly to ignore the ‘sticky’ posts when filtering BUT only IF I use a S&F search box (input) for the initial search (which is on the home page, the ‘filters’ are added on the search results page). I can’t do that, because using an S&F search input box doesn’t take into account sticky posts in the INITIAL results (pre-filtering), so those sticky posts are mixed in with the others in whatever is the sort order chosen in the configuration for that search input, instead of being at the top as a sticky post ordinarily would be.
If I use the stock WP search function/form to initiate the search, I get the sticky posts where they should be at the top of all results, but then when filtering, they stay there even though they do not match the filters applied (whether I use AND or OR), I think it’s because the search parameter is not changing (a WP thing) so the filter is being applied on top of the existing search phrase and ignoring the AND/OR operator.
So what I need is a way to say “hey if there are sticky posts, they go at the top *except* if they don’t apply according to the filters being used”….then they should be weeded out as any non-matching result would be.
**UPDATED**
P.S. I forgot to mention another reason I cannot use an S&F search input box for the initial search – it does not work with the Search Autocomplete plugin we use to autocomplete/suggest search terms – in that Plugin’s settings I did use the correct name for the search box, but noticed in the source code that the input has a hard-coded setting (from the S&F Pro plugin) that sets autocomplete to “off” so it doesn’t work.Ross Moderator(Private) April 15, 2015 at 1:14 am #15077Hey Trisha
Thanks for the updates.
Yeah sounds like you might be in a tricky situation.
Can you explain in more detail why S&F doesn’t work with the autocomplete? S&F doesn’t switch anything “off”, but then again it doesn’t switch anything “on” either – if its a small modification to make to enable S&F to work with the autocomplete plugin then I’d happily provide some work arounds (if I can think of any)
What auto complete plugin are you using?
Thanks
Anonymous(Private) April 15, 2015 at 5:36 pm #15138Hi Ross,
Thank you….the plugin I’m using is Search Autocomplete by Gabe Shackle:
https://wordpress.org/plugins/search-autocomplete/
The plugin has some settings, so we have it configured to ONLY use the custom taxonomies we have for the autocomplete dropdown….it doesn’t stop folks from typing in anything, but it offers suggestions based on what content we do have.
I’m probably misunderstanding the code that constructs the search box and submit button…..on the home page where the initial search box is, we want a submit button, so in the S&F configuration I have “autosubmit” unchecked……when the form is rendered, the input that is the submit button is this:
<input autocomplete="off" class="ui-autocomplete-input" name="_sf_submit" value="Submit" type="submit">
But after testing, even with a search box with the autosubmit checked (meaning no submit button is displayed), our ‘autocomplete’ does not work……it only works with the standard WP search box/form….so I don’t think the problem is related to the autosubmit setting.
-
AuthorPosts