Title: incorrect function dwqa_get_latest_answer()
Last modified: November 9, 2017

---

# incorrect function dwqa_get_latest_answer()

 *  [sajjad](https://wordpress.org/support/users/sajjad203/)
 * (@sajjad203)
 * [8 years, 6 months ago](https://wordpress.org/support/topic/incorrect-function-dwqa_get_latest_answer/)
 * Hi,
 * You have function dwqa_get_latest_answer() in inc/status.php.
 * This function not work correctly!
    You have this code in it:
 *     ```
       function dwqa_get_latest_answer( $question_id = false ) {
       	if ( !$question_id ) {
       		$question_id = get_the_ID();
       	}
   
       	// When we get latest answer by normal query it take a long time to query into database so i will try to setup transien here to improve it. Of course we will use another cache plugin for QA site in additional
       	$latest = get_transient( 'dwqa_latest_answer_for_' . $question_id );
       	if ( false === $latest ) {
       		$args = array(
       			'post_type' 		=> 'dwqa-answer',
       			'meta_query' 		=> array(
       				array(
       					'key' 		=> '_question',
       					'value' 	=> $question_id,
       					'compare' 	=> '=',
       				),
       			),
       			'post_status'    	=> 'public,private',
       	    	'numberposts' 		=> 1,
       		);
       		$recent_answers = wp_get_recent_posts( $args, OBJECT );
       		if ( count( $recent_answers ) > 0 ) {
       			$latest = $recent_answers[0];
       			// This cache need to be update when new answer is added
       			set_transient( 'dwqa_latest_answer_for_' . $question_id, $latest, 450 );
       		}
       	}
   
       	return $latest;
       }
       ```
   
 * $latest = get_transient( ‘dwqa_latest_answer_for_’ . $question_id ); return string
   0 for some questions and not go to the condition because of Strict Equality Comparison(
   ===). So it return string 0 in final!
 * And the post_status is public while it should be publish.
 * So please change `if ( false === $latest )` to `if ( false == $latest )` and `'
   post_status' => 'public,private'` to `'post_status' => 'publish,private'` to 
   work correctly.
 * Thank you

The topic ‘incorrect function dwqa_get_latest_answer()’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/dw-question-answer_fefdf9.svg)
 * [DW Question & Answer](https://wordpress.org/plugins/dw-question-answer/)
 * [Support Threads](https://wordpress.org/support/plugin/dw-question-answer/)
 * [Active Topics](https://wordpress.org/support/plugin/dw-question-answer/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/dw-question-answer/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/dw-question-answer/reviews/)

 * 0 replies
 * 1 participant
 * Last activity: [8 years, 6 months ago](https://wordpress.org/support/topic/incorrect-function-dwqa_get_latest_answer/)
 * Status: not resolved