Billy Bagins
asked 6 years ago

I want to display answers by votes (top voted on top and then newest answers with no votes). 
I have added the following meta key and order (in my dwqa-templates/answers.php), but it only works if answer has at least one vote.

  
  

	   'meta_key' => '_dwqa_votes',
	   'orderby' => 'meta_value_num',

  
  
 $args = array(
       'post_type' => 'dwqa-answer',
       'posts_per_page' =>  -1,
       'order'      => 'DESC',
	   'meta_key' => '_dwqa_votes',
	   'orderby' => 'meta_value_num',
       'meta_query' => array(
           array(
               'key' => '_question',
               'value' => array( $question_id ),
               'compare' => 'IN',
           )
       ),
       'post_status' => $status
     );

Can you help me to solve this problem? I’m just a beginner.

shirodx
replied 2 years ago

Can you tell me how to do this please? Do I just copy and paste this into the answers.php file directly?

2 Answers
Guru
answered 6 years ago

Thats a good dig, Billy!
I will see if I can test it out on my end. and any help from DW team would be appreciated.

BigHug
answered 6 years ago

Hi Billy, 
You can use relation OR and value NOT EXISTS in meta query of your query like this 

 'meta_key' => '_dwqa_votes',
'orderby' => 'meta_value_num',
'meta_query' => array(
    'relation' => 'OR',
array(
'key' => '_dwqa_votes',
'compare' => 'NOT EXISTS'
)
),

Regards

Powered by DW Question & Answer Pro