Shakib Taha
asked 6 years ago

At the moment, when a User selects ‘view questions’ – it will show ALL Questions regardless if they are answered or unanswered. 
example:
if you go to https://www.designwall.com/question/
you will see that the default filter is ‘ALL’ and not answered or un-answered etc. 
where do i make changes to enable a different default filter?

2 Answers
DominicStaff
answered 6 years ago

You can use the following code in the functions.php file in your theme: 
http://snippi.com/s/3xctth2

Dominic Staff
replied 6 years ago

Then replace the Filter name in the line 6.

Shakibt
replied 6 years ago

Hey Dominic – thanks for that – Although, trying to look for an alternative and avoid editing something outside the plugin code itself. I think it’s pretty silly to have to edit the theme for a dependency i would expect internal to the plugin framework and set of code. Having reviewed it the set of code and plugin, what you could do is edit inc/filter.php

under the public function prepare_archive_posts, you’re already defining a set number of Arrays – although calling for each argument to be stored in $filter, just pre-define the variable.

So, before going into the switch ( $filter ), add a $filter = ‘resolved’;

in other words, what’s in the snippi link above but within your plugin codeset.

many thanks,

Dominic Staff
replied 6 years ago

At the moment, you should filter and add code outside the plugin. Will save for the plugin update.

Fabian
answered 5 years ago

Hi , now, one year after, ¿can we configure the default filter in a easier way?

Dominic Staff
replied 5 years ago

At the moment, you only use the custom code to resolve this issue.

Fabian
replied 5 years ago

add_filter(‘dwqa_prepare_archive_posts’, ‘dwqa_custom_filter’, 10, 1);
function dwqa_custom_filter($query){
if(!isset( $_GET[‘filter’] ) || empty( $_GET[‘filter’] )){
// filter by status
$filter = ‘all’;
switch ( $filter ) {
case ‘open’:
$query[‘meta_query’][] = array(
‘key’ => ‘_dwqa_status’,
‘value’ => array( ‘open’, ‘re-open’ ),
‘compare’ => ‘IN’,
);

This change is correct to show all questions?

Dominic Staff
replied 5 years ago

Why do you need to change the code to display all questions while defaulting of the plugin is showing all the question.

Powered by DW Question & Answer Pro