Support » Fixing WordPress » custom comment fields inside custom post type

  • dynamyc


    I have a custom post type and I want to create 2 new fields and remove the default ones (author,url,email) without affecting the default comment fields inside the blog posts.

    Also I want to make it visible just for logged in users, with a message like this for non-logged in users:

    You must be logged in to post a comment

    I’ve noticed that I can do this from the dashboard setting but the problem is that this will be applied to all the comments and I want to apply this just on a specific CPT.

    So, here is my approach:

    function debate_comment_fields( $fields ) {
     if( is_singular( 'debate' ) ) {
         $fields['url'] = '';
        $fields['author'] = '';
        $fields['email'] = '';
        $fields['first'] = '<p class="comment-form-first"><label for="first">' .
                         __( 'HTML5' ) .
                         '</label>' .
                         '<input id="first" name="category" type="radio" value="'.get_post_meta($post->ID, 'agree', true).'" /></p>';
        $fields['second'] = '<p class="comment-form-second"><label for="second">' .
                           __( 'FLASH' ) .
                           '</label>' .
                          '<input id="second" name="category" type="radio" value="'.get_post_meta($post->ID, 'disagree', true).'" /></p>';
        return $fields;

    This code is removing the default fields also on the blog posts and I don’t want this.
    After I submit a comment inside my CPT I get this:
    ERROR: please fill the required fields (name, email).

    And also how can I add a message if the user is not logged in like this:

    You must be logged in to post a comment

    just on my CPT.

  • The topic ‘custom comment fields inside custom post type’ is closed to new replies.