• sajjad

    (@sajjad203)


    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.