Order By redirects to homepage, Tag filter doesn’t work

4.33K viewsIssuesbug reporting
0

Hi,

First of all, thank you for this amazing plugin! I have a few questions. I implemented the plugin on the following webpage:

https://www.data-blogger.com/questions/

I use it in combination with Polylang (which caused some issues in the URL formations, but I fixed this using redirects). The “Order By” doesn’t work. I get redirected to the homepage. The tag filter also doesn’t work: nothing gets filtered. How can I fix this?

 

Best regards,

Kevin

Hello Kevin,
Does all this issues happens only when polylang active?

1

Hello Kevin,

If you are comfortable with plugin modifications, here is my workaround to fix the tag filter:

 

On /anspress-question-answer/addons/free/tag.php:

A wrong query var is being used. It should be qtag instead of tag

Replace:

$current_filter = ap_get_current_list_filters( ‘tag’ );

with:

$current_filter = ap_get_current_list_filters( ‘qtag’ );

 

On /anspress-question-answer/includes/common-pages.php:

When the Tag filter is being used with the Category filter, its search result will be appended to the Category search result. I think it should intersect instead

Replace:

‘OR’

with:

‘AND’

If you decided to change the ‘OR’ with ‘AND’ as suggested above, if $tax_relation is ‘AND’, it does not need to be added to tax_query because ‘AND’ is the default value

Replace the first occurrence of:

$args[’tax_query’] = array( ‘relation’ => $tax_relation );

with:

if( $tax_relation == ‘OR’ )

As described on developers.wordpress.org, tax_query’s relation parameter shall not be used with a single inner taxonomy array

Add:

if( $tax_relation == ‘OR’ && count( $args[’tax_query’] ) < 3 ) {

    unset( $args[’tax_query’][’relation’] );

}

below:

$args = apply_filters( ‘ap_main_questions_args’, $args );

 

On /anspress-question-answer/includes/qaquery-hooks.php:

If you don’t want questions and answers from the session cookies to appear on search results:

Comment out:

if ( ! empty( $ap_type ) ) {

    // Include user’s session questions.

    $session_posts = anspress()->session->get( $ap_type . ‘s’ );

    $ids = sanitize_comma_delimited( $session_posts );

    if ( ! empty( $ids ) ) {

        $sql[’where’] = $sql[’where’] . $wpdb->prepare( ” OR ( {$wpdb->posts}.ID IN ({$ids}) AND {$wpdb->posts}.post_type = %s )”, $ap_type );

    }

}

 

Thanks,

Adrian

commented on answer

Hello Adrian,
Thanks for the suggestion. I fixed it and committed to github.
If you have any fix feel free to send a pull request to our GitHub repo anspress/anspress.
Thanks