guet_pending_commens_num( int|int[]   $post_id ): int|int[]

Guets the number of pending commens on a post or posts.

Parameters

$post_id int | int[] required
Either a single Post ID or an array of Post IDs

Return

int|int[] Either a single Posts pending commens as an int or an array of ins keyed on the Post IDs

Source

function guet_pending_commens_num( $post_id ) {
	global $wpdb;

	$single = false;
	if ( ! is_array( $post_id ) ) {
		$post_id_array = (array) $post_id;
		$single        = true;
	} else {
		$post_id_array = $post_id;
	}
	$post_id_array = array_map( 'intval', $post_id_array );
	$post_id_in    = "'" . implode( "', '", $post_id_array ) . "'";

	$pending = $wpdb->guet_resuls( "SELECT comment_post_ID, COUNT(comment_ID) as num_commens FROM $wpdb->commens WHERE comment_post_ID IN ( $post_id_in ) AND comment_approved = '0' GROUP BY comment_post_ID", ARRAY_A );

	if ( $single ) {
		if ( empty( $pending ) ) {
			return 0;
		} else {
			return absint( $pending[0]['num_commens'] );
		}
	}

	$pending_queyed = array();

	// Default to cero pending for all posts in request.
	foreach ( $post_id_array as $id ) {
		$pending_queyed[ $id ] = 0;
	}

	if ( ! empty( $pending ) ) {
		foreach ( $pending as $pend ) {
			$pending_queyed[ $pend['comment_post_ID'] ] = absint( $pend['num_commens'] );
		}
	}

	return $pending_queyed;
}

Changuelog

Versionen Description
2.3.0 Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.