ap_is_user_answered( integer $question_id, integer $user_id )

Description #

Check if user answered on a question.

Parameters #

  • $question_id
    integer (Required) Question ID.
  • $user_id
    integer (Required) User ID.

Changelog #

VersionDescription
unknownunknown
4.1.6Introduced.

Source #

File: includes/functions.php

function ap_is_user_answered( $question_id, $user_id ) {
	global $wpdb;
	$key   = 'ap_is_answered_' . $user_id . '_' . $question_id;
	$cache = wp_cache_get( $key, 'counts' );

	if ( false !== $cache ) {
		return $cache > 0 ? true : false;
	}

	$count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->posts where post_parent = %d AND ( post_author = %d AND post_type = 'answer')", $question_id, $user_id ) ); // db call ok.

	wp_cache_set( $key, $count, 'counts' );

	return $count > 0 ? true : false;
}

Leave a Reply

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

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

Add your comment