Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I want to add two custom fields inside comments on a CPT after the user is logged in on.

This is the code for creating the custom fields:

function debate_comment_fields( $fields ) {

if( is_singluar('debate') ) {


    /* Add our custom fields */
    $fields['first'] = '<p class="comment-form-first"><label for="first">' . 
                     __( 'Age' ) . 
                     '</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">' . 
                       __( 'Town' ) . 
                       '</label>' .
                      '<input id="second" name="category" type="radio" value="'.get_post_meta($post->ID, 'disagree', true).'" /></p>';

    return $fields;

}

}

add_filter('comment_form_default_fields','debate_comment_fields');

LATER EDIT: some relevant code from my theme comments.php file:

// Don't output the comment form if CPT and user isn't logged in
if ( 'debate' != get_post_type() || is_user_logged_in() ) {
comment_form( $args );
}
?>

The current code adds the fields when the user is not logged in, and I want to add them after the user is logged in.

How can I do this ?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

I believe you want is_user_logged_in

if(is_singular('debate') && is_user_logged_in()) {
  // ...
}

(Note: is_singular is misspelled in your code.)

share|improve this answer
    
Tried this but it's not working, I mean is not adding the custom fields... –  agis Nov 14 '13 at 16:22
    
Then you need to provide more information –  s_ha_dum Nov 14 '13 at 16:49
    
I've updated my question with some relevant additional info, please check it out! –  agis Nov 14 '13 at 19:50
    
The edit doesn't change anything. –  s_ha_dum Nov 14 '13 at 20:09
    
I don't know what relevant information I can provide, can you help me with this? –  agis Nov 14 '13 at 20:47

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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