ap_total_solved_questions( string $type = 'int' )

Description #

Get total numbers of solved question.

Parameters #

  • $type
    string (Optional) Valid values are int or object. Default value: 'int'

Source #

File: includes/functions.php

function ap_total_solved_questions( $type = 'int' ) {
	global $wpdb;
	$query = "SELECT count(*) as count, p.post_status FROM $wpdb->posts p INNER JOIN $wpdb->ap_qameta qameta ON p.ID = qameta.post_id WHERE p.post_type = 'question' AND qameta.selected_id IS NOT NULL AND qameta.selected_id > 0 GROUP BY p.post_status";

	$count  = $wpdb->get_results( $query, ARRAY_A ); // phpcs:ignore WordPress.DB
	$counts = array( 'total' => 0 );

	foreach ( get_post_stati() as $state ) {
		$counts[ $state ] = 0;
	}

	foreach ( (array) $count as $row ) {
		$counts[ $row['post_status'] ] = (int) $row['count'];
		$counts['total']              += (int) $row['count'];
	}

	$counts = (object) $counts;
	if ( 'int' === $type ) {
		return $counts->publish + $counts->private_post;
	}

	return $counts;
}

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Add your comment