In a template file that I am using as page, I want to allow only 2 users to post comments and allow to all other users to only see these comments( not allow them add comments).

my template file is:

<?php get_header();  ?>

if (get_current_user_id()==1 or get_current_user_id()==2 ) {

comments_template( '', true );
comments_template( '/comments-with-no-form.php', true );

} ?>

<?php get_footer(); ?>

Normally, when I remove comments_template from single.php, or just remove the <?php comment_form(); ?> from comments.php, changes apply. But in separate template file, nothing is working. The file comments-with-no-form.php is never executed (only style of comments.php changes).

Your help is appreciated.


This if statement is really wrong :

if (get_current_user_id()==1 or get_current_user_id()==2 

should be :

$user_id = get_current_user_id();
if ($user_id==1 || $user_id==2 )
| improve this answer | |
  • waw. I was thinking the problem is in comments_template. what is wrong in my statement? is is the or. – whiteletters in blankpapers Jul 2 '13 at 15:23
  • Ahhhh, In my editor I saw its color changing, my god I thought my editor know only PHP. :-) thanks man – whiteletters in blankpapers Jul 2 '13 at 15:29
  • 2
    or is a valid logical operator – s_ha_dum Jul 2 '13 at 15:39
  • I was wrong this is not due to or but the way you called get_current_user_id() and use it. Sorry :/ – JMau Jul 2 '13 at 15:56

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.