Exciting News! Flipper Code is now WePlugins! Same commitment to excellence, brand new identity.

How to use get_adjacent_post_excluded_terms filter in WordPress

Sandeep Kumar Mishra
Sandeep Kumar Mishra
March 26, 2023
5 minutes read

As a WordPress developer, you’ll often need to customize how your site behaves. One such way is through hooks, and today we’re diving into the get_adjacent_post_excluded_terms filter. This hook is pretty nifty when you want to manage the adjacent posts’ excluded terms dynamically. Let’s make it easy by exploring some live examples.

Example 1: Modifying Excluded Terms

Want to adjust the excluded terms for adjacent posts? Here’s a straightforward way to do it. This example modifies the excluded terms according to your specific requirements.

    function weplugins_modify_get_adjacent_post_excluded_terms_defaults($excluded_terms) { 
        // Update the $excluded_terms variable according to your website requirements
        return $excluded_terms; 
    }
    // add the filter
    add_filter("get_adjacent_post_excluded_terms", "weplugins_modify_get_adjacent_post_excluded_terms_defaults", 10, 1);
    

Example 2: Applying the Filter

Here’s how you can apply the get_adjacent_post_excluded_terms filter in your theme or plugin. This example shows the basic structure of using the filter.

    apply_filters("get_{$adjacent}_post_excluded_terms", $excluded_terms);
    

Example 3: Removing a Filter

If you need to remove this filter for some reason, here’s how you can do it. Just ensure the callback function name, priority, and arguments match what you used when adding it.

    remove_filter("get_adjacent_post_excluded_terms", "weplugins_modify_get_adjacent_post_excluded_terms_defaults", 10, 1);
    

Access Premium WordPress Plugins

Contact Us

If you’re facing any issues or need custom solutions, feel free to Contact Us. We’re here to help!

Sandeep Kumar Mishra

Sandeep Kumar Mishra

Sandeep Kumar Mishra writes about WordPress and Artificial Intelligence, offering tips and guides to help you master your website and stay updated with the latest tech trends.

Explore the latest in WordPress

Trying to stay on top of it all? Get the best tools, resources and inspiration sent to your inbox every Wednesday.