Exclude Posts by ID Programmatically

Forums › Forums › Search & Filter Pro › Exclude Posts by ID Programmatically

Tagged: 

Viewing 2 posts – 1 through 2 (of 2 total)
  • Anonymous
    #217342

    I have a S&F Form and need to find a way to exclude 3 posts from the results programmatically. I know the form settings have the exclude options, but the 3 posts will be changing, so I can’t set them in the settings.

    I have a function that retrieves the 3 IDs I need to exclude and puts them into an array. So trying to figure out a way to say…For a specific S&F form (because I have multiple S&F forms and only need this for one specific one), exclude these 3 posts from results. I feel like there is a filter or hook to do this, I’m just not sure how to create it.

    So lets say my S&F form has an ID of 287

    Then my function that returns an array of post ID’s is excluded_posts(). I’ve tested my function and does properly return an array of the 3 needed IDs

    Any help would be greatly appreciated.

    Trevor
    #217391

    You would need to use the post__not_in argument for WP Query, and use this in a function inside your child theme’s functions.php file.

    Then add this to our query using this filter:

    https://searchandfilter.com/documentation/action-filter-reference/#edit-query-arguments

Viewing 2 posts – 1 through 2 (of 2 total)
Search & Filter Support
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

We also use cookies to store items in your cart as well as allowing your to login on the site.

You can adjust all of your cookie settings by navigating the tabs on the left hand side.

By continuing to use this site, you also agree to our Privacy Policy.