Pets_QandA
asked 7 years ago

Although the "Answers" shows "1" (answered by a registered user), the question remains in an Unanswered state. Only when a question is answered by a non-registered user, does it indicate as "Answered" (the blue arrow).

Where can I change this that it always show an Answered indicator?
Wouldn’t it make more sense to do it other way round, only show on registered users answers?

Also, no "Answered" filter?

3 Answers
DominicStaff
answered 7 years ago

To resolve this issue, you can open the wp-content -> plugins -> dw-question-answer -> inc -> status.php file and replace the line 354 to line 370 with the following code:

public function dwqa_auto_change_question_status( $answer_id ){
        if ( ! is_wp_error( $answer_id ) ) {
            $question_id = get_post_meta( $answer_id, '_question', true );
            $answer = get_post( $answer_id );
            if ( $question_id && $answer->post_author ) {
                $question_status = get_post_meta( $question_id, '_dwqa_status', true );
                if ( dwqa_current_user_can( 'post_answer' ) ) {
                    update_post_meta( $question_id, '_dwqa_status', 'answered' );
                } else {
                    if ( $question_status == 'resolved' || $question_status == 'answered' ) {
                        update_post_meta( $question_id, '_dwqa_status', 'open' );
                    }
                }
            }
        }
    }
}

If you have any question or still face their issue, you can send me username & password for your site for further checking.
Hope this helps!

Pets_QandA
answered 7 years ago

I think you added one too many closing curly braces in the code snippet.

So this will only change the status, when answering a question (current user can post_answer), right? It won’t update any other, already answered questions. I mean, it doesn’t change the way the status is displayed, only the way it is updated to Answered upon answering. I mean, wouldn’t it make more sense, when count of answers is > 0, it is in fact Answered?

Pets_QandA
answered 7 years ago

Anyway,
I changed /inc/Status.php ln24 from

if ( $status ) {
        $return = '<span title="'.__( ucwords( $status ), 'dwqa' ).'" class="dwqa-status dwqa-status-'.strtolower( $status ).'">'.__( ucwords( $status ), 'dwqa' ).'</span>';

        if ( $echo ) {
            echo $return;
            return;
        }
        return $return;
    }

to

if ( $status ) {
        $answers_count = dwqa_question_answers_count();
        if($answers_count > 0 && $status == 'open'){
            $status = 'answered';
        }
        $return = '<span title="'.__( ucwords( $status ), 'dwqa' ).'" class="dwqa-status dwqa-status-'.strtolower( $status ).'">'.__( ucwords( $status ), 'dwqa' ).'</span>';

        if ( $echo ) {
            echo $return;
            return;
        }
        return $return;
    }

adding the answer count. And if count is > 0, but status is still open, I change the local $status variable to ‘answered’, so it picks up the css stylename, and shows answered indicator. And it works for me.

Powered by DW Question & Answer Pro