How to show comments from a post by id. WordPress Code examp... open

How to show comments from a post by id. WordPress Code example

Approved. Code works!
This is exactly the working code that is verified by the moderator or site administrators
		$other_post_id = 787;

		$other_post_comments = get_comments( array(
			'post_id' => $other_post_id,
		) );
		echo '<div id="comments" class="themeform home-comments">';
		foreach ( $other_post_comments as $comment ) {
			$comment = get_comment( $comment ); 
		
			echo '<div ' . ' id="comment-' . $comment->comment_ID . '" class="home-comment">';

			echo '<div class="comment-author vcard">';
			echo get_avatar( $comment, 50 );
			echo '<cite class="fn">' . get_comment_author_link( $comment ) . '</cite>';
			echo '</div>';

			echo '<div class="comment-meta commentmetadata">';
			printf(
				__( '%1$s at %2$s', 'text-domain' ),
				get_comment_date( '', $comment ),
				get_comment_time(),
			);
			echo '</div>';

			echo '<div class="comment-content">';
			comment_text( $comment );
			echo '</div>';

			echo '</div>';
		}

		comment_form( array(
			'comment_post_ID' => $other_post_id,
			'id_form' => 'commentform',
			'class_form' => 'comment-form',
		), 787 );
		echo '</div>';

Remove redirect to this post after publication

function redirect_after_comment_submission($location, $comment) {
    $post_id = 787; 
    if ($comment && $comment->comment_post_ID == $post_id) {
        $location = home_url();
    }
    return $location;
}
add_filter('comment_post_redirect', 'redirect_after_comment_submission', 10, 2);
0

More

Leave a Reply

Your email address will not be published. Required fields are marked *

How many?: 22 + 22

lil-code© | 2022 - 2024
Go Top
Authorization
*
*
Registration
*
*
*
*
Password generation