2

I like to have comments be approved being posted, however I have a custom content type that I want comments to go through without moderation. Is this possible with a php function for only the custom content type? Thanks.

1

Yes, it is possible using wp_insert_comment hook. To approve comments automatically for custom post types you can use something similar to this:

//hook to do stuff with comments
add_action( 'wp_insert_comment', 'approve_comment', 99, 2 );

function approve_comment($comment_id, $comment_object) {
   //get id of the post that was commented
   $post_id = $comment_object->comment_post_ID;

   //approve comment for "post" type
    if( 'post' == get_post_type( $post_id )) {
       $retrieved_comment = get_comment( $comment_id, ARRAY_A );
       //approve comment    
       $commentarr = $retrieved_comment;
       $commentarr['comment_ID'] = $comment_id;
       $commentarr['comment_approved'] = 1;
       wp_update_comment( $commentarr );
   }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.