• Hi all.
    Trying to auto filter posts to categories based on content ie: if the content contains the word “apple” categorise as “fruit.
    So far I have:

    add_action( 'save_post', 'auto_catg', 10, 2 );
    
    function auto_catg($post){
    					$data = $post['post_content'];
    					$data = strtolower($data);
    								//Condition for FRUIT
    		 if (
    					strpos($data, 'apple')!==false
    					or
    					strpos($data, 'pear')!==false
    					or
    					strpos($data, 'grape')!==false
    				) {
                           $post[post_category] = wp_set_object_terms( $post['ID'], 3, 'category', true );
    					   $scam_cat = $post[post_category];						  }	
    
    		  					//Condition for HERBS
    		  elseif (
    		  			strpos($data, 'mint')!==false 
    
    				) {
             			   $post[post_category] = wp_set_object_terms( $post['ID'], 4, 'category', true );
    				  }
    
    		  		   return ($post);
    
    }

    Its very late so that may be a factor but I cannot see why this is not working?
    Any help appreciated.

Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Filter to category pre publishing’ is closed to new replies.