Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- https://wordpress.stackexchange.com/questions/295188/conditional-if-current-user-has-not-commented-on-current-post/295211
- <?php
- wp_reset_postdata();
- $post_id = get_the_ID(); // ID of the current post.
- $user_id = get_current_user_id(); // ID of the current user.
- $post_author_id = get_post_field( 'post_author', $post_id );
- $comment_count = 0;
- // Get the number of comments made by the current user on the current post.
- if ( $user_id && $post_author_id != $user_id ) {
- $comment_count = get_comments( array(
- 'post_id' => $post_id,
- 'user_id' => $user_id,
- 'count' => true,
- ) );
- }
- // The user has not yet commented on the current post. So do the something.
- // Or, the user has already commented; but the post is his or her own post.
- if ( ! $comment_count ) { ?>
- please leave a response
- <?php } else { ?>
- thanks for your response
- <?php } ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement