• Hi All,
    I am trying to create a function to search “the_content” for specific phrases eg “football’ or “tennis” or “swimming”
    If it finds these phrases then the category “Sports” is assigned

    However if any of the phrases “whiskey”, “beer” or “rum” are found then category “Drinks” is assigned.
    both “Sports” and “Drinks” are existing categories.

    I am using the plugin Postie and the filter would be called before the post is published.

    I try to learn by trial and (lots of) error and my current function is:

    function filter_tocat( $content ) {
    	$sportfilter = array('football','tennis','swimming');
    	$category = wp_set_post_categories( $sportfilter, 'Sports', $category );
    	return $category;
    }

    I know this is currently ridiculously wrong but this is the point that I am pulling my hair out!
    Any advice would be appreciated.

  • The topic ‘Filter "the_content" to assign a preexisting category’ is closed to new replies.