• Resolved thelevicole

    (@thelevicole)


    I have taxonomy filters on the frontend that are reloaded with ajax but don’t keep their order because the is_admin() function returns true on ajax requests.

    A fix could be to change the condition in your front_end_order_terms method from:

    if ( ! is_admin() && apply_filters( 'yikes_simple_taxonomy_ordering_front_end_order_terms', true ) ) {

    To:

    if ( ( ! is_admin() || wp_doing_ajax() ) && apply_filters( 'yikes_simple_taxonomy_ordering_front_end_order_terms', true ) ) {

    Or:

    if ( ! is_admin() && apply_filters( 'yikes_simple_taxonomy_ordering_front_end_order_terms', true ) || apply_filters( 'taxonomy_ordering_ajax', false ) ) {

    And developers can then do something like…

    
    add_filter( 'taxonomy_ordering_ajax' '__return_true' );
    get_terms()
    add_filter( 'taxonomy_ordering_ajax' '__return_false' );
    
Viewing 1 replies (of 1 total)
  • Thread Starter thelevicole

    (@thelevicole)

    I’ve implemented a quick fix my end with the following…

    if ( class_exists( 'Yikes_Custom_Taxonomy_Order' ) && wp_doing_ajax() ) {
        add_filter( 'terms_clauses', [ Yikes_Custom_Taxonomy_Order::get_instance(), 'set_tax_order' ], 15, 3 );
    }
    
    $terms = get_terms( $args );
    
    if ( class_exists( 'Yikes_Custom_Taxonomy_Order' ) && wp_doing_ajax() ) {
        remove_filter( 'terms_clauses', [ Yikes_Custom_Taxonomy_Order::get_instance(), 'set_tax_order' ], 15 );
    }
Viewing 1 replies (of 1 total)
  • The topic ‘Ordering isn’t applied in AJAX requests’ is closed to new replies.