-1

I want to change the default comment form title_reply, label_submit ... just on my CPT without affecting the default comment form but I can't get it to work without affecting the default ones.

First I don't want to output the comment form if CPT and user isn't logged in, I'm doing this with this code:

// Don't output the comment form if CPT and user isn't logged in
if ( 'myCPT' != get_post_type() || is_user_logged_in() ) {
 comment_form(array('title_reply'=>'Got Something To Say:'));
 }

Which is working fine, but I want also to check if CPT exists and alter the default comment form if I'm inside that CPT. Now the question will be how can I put this together ?

Thank you!

0

2 Answers 2

0

You're logic reads like this: "If the post type is not 'myCPT' or if the user is logged in, then use the altered comment_form" So, all post types except myCPT use the altered form and any user that is logged in will see the altered form.

That doesn't sound like your description of the problem:

I want to change the default comment form title_reply, label_submit ... just on my CPT without affecting the default comment form...

Nor does it sound like the description of what you think the code should do in the comment:

Don't output the comment form if CPT and user isn't logged in

There are at least two descriptions of what should be happening and the code does neither-- not even close.

Assuming the simplest case that you want to change the defaults for the comment form for your CPT, then...

if ( 'myCPT' == get_post_type()) {
  if (is_user_logged_in()) {
     comment_form(array('title_reply'=>'Got Something To Say:'));
  }
} else {
  comment_form();
}
3
  • Sorry, I forgot to mention that I need in addition to the existing code to check also if there is a CPT and alter the default comment form if that CPT exists. I've updated my question.
    – agis
    Nov 24, 2013 at 17:32
  • Edited to incorporate the what I think is the logged in logic you want.
    – s_ha_dum
    Nov 24, 2013 at 17:49
  • To be more clear: I want to hide the comment form if user is not logged in and the CPT exists and if the user is logged in and CPT exists to display different title_reply
    – agis
    Nov 24, 2013 at 18:57
0

Your problem is your PHP conditional. You're saying "if A or B, then do something", but that's not what you really want to do.

Try manipulating the arguments array directly, and then passing it to the comment form:

if ( is_user_logged_in() ) {

    $comment_form_args = array();

    if ( 'myCPT' == get_post_type() ) {
        $comment_form_args['title_reply'] = 'Got Something To Say:';
    }

    comment_form( $comment_form_args );
}

Edit

If you don't need the is_user_logged_in() conditional, just remove it:

$comment_form_args = array();

if ( 'myCPT' == get_post_type() ) {
    $comment_form_args['title_reply'] = 'Got Something To Say:';
}

comment_form( $comment_form_args );
6
  • Sorry, I forgot one important aspect to mention, I've updated my question.
    – agis
    Nov 24, 2013 at 17:33
  • see edited answer. If you don't need the is_user_logged_in() conditional, just remove it. Nov 24, 2013 at 17:46
  • The same, I want to keep my current if conditional code and in addition to it to check for the CPT and output different title_reply within the CPT. How can I integrate your code inside the code I've posted ?
    – agis
    Nov 24, 2013 at 18:41
  • I don't understand what you're asking. Nov 24, 2013 at 18:45
  • I want to hide the comment form if user is not logged in and the CPT exists and if the user is logged in and CPT exists to display different title_reply.
    – agis
    Nov 24, 2013 at 18:55

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