WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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;




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
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


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.