WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Hook add filter to the content and exclude posts from a certain category (2 posts)

  1. Leon
    Member
    Posted 4 years ago #

    Hi,

    I am adding a filter to the content with my plugin, which adds a link to certain keywords.

    Now I want to exclude certain posts which are in a particular category.

    In other ways, only apply the filter to posts which are not in that category. Anybody knows if this is possible?

    function filter_content()
    {
     //content stuff here
    }
    
    add_filter('the_content', 'filter_content', 999);

    thanks!

  2. Leon
    Member
    Posted 4 years ago #

    I found a way to do this,

    in the function that filters add the following:

    $get_category = get_the_category();
    if(strtolower($get_category[0]->cat_name) != 'catname')
    {
    //the actions to perfom on the content
    }

    this only applies when the certain category you want to exlcude is the first category assigned to the post. If you want to exclude more, you can do an array search.

Topic Closed

This topic has been closed to new replies.

About this Topic