Random WordPress Function

Learn about a new WordPress function every day!


Function Signature:

wp_get_comment_status

Function Description:

Retrieves the status of a comment by comment ID.

Function Examples:

⚠️ Examples below are generated with GPT-3 once every hour. Do not take them too seriously.
Consider them as some extra input in your learning process - reason about them. Will it work? What could fail?
// Example 1: Get the status of a specific comment by passing the comment ID
$comment_id = 25;
$comment_status = wp_get_comment_status( $comment_id );
if ( $comment_status ) {
    echo "The status of comment with ID $comment_id is: $comment_status";
} else {
    echo "Comment with ID $comment_id does not exist.";
}
// Example 2: Check if a comment is approved or not before displaying it on the website
$comment_id = 15;
$comment_status = wp_get_comment_status( $comment_id );
if ( $comment_status === 'approved' ) {
    // Display the comment on the website
    echo "Approved comment: " . get_comment_text( $comment_id );
} else {
    // Do not display unapproved comments
    echo "This comment is not approved and cannot be displayed.";
}
// Example 3: Get the status of all comments on a specific post
$post_id = 10;
$comments = get_comments( array( 'post_id' => $post_id ) );
foreach ( $comments as $comment ) {
    $comment_id = $comment->comment_ID;
    $comment_status = wp_get_comment_status( $comment_id );
    echo "Comment ID: $comment_id, Status: $comment_status 
"; }