• I’d like to test a single post to see if it has a comment and if so I’d like to put that into a category automatically say category id 12 for instance… Ideally this would happen once someone submits a comment.

    Any Ideas?!?

    Thanks!!!

Viewing 3 replies - 1 through 3 (of 3 total)
  • This would probably be done with a filter, which you can learn more about here. You’d basically create a function to run when a comment is added to the database, and then attach that function to the correct filter.

    Thread Starter bjrdesign

    (@bjrdesign)

    Thanks for the help… I get the concept and almost have it working however I am stuck at the updating the post category… This is what I have so far…

    function markTaken(){
    	wp_set_object_terms( $post_id, 12, 'category', true );
    }
    
    add_filter ( 'comment_post', 'markTaken' );

    However this results in the following error…

    Warning: Cannot modify header information – headers already sent by (output started at /home/calvary/public_html/calvaryglobalkids.org/wp-content/themes/yoko/functions.php:138) in /home/calvary/public_html/calvaryglobalkids.org/wp-includes/pluggable.php on line 934

    Any help would be greatly appreciated!

    I believe that comment_post is an action, not a filter. So instead of using add_filter, it would be:

    add_action( 'comment_post', 'markTaken' );

    Not sure if that will fix the issue or not, but hopefully

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Change Post Category If Has Comment’ is closed to new replies.