• Resolved coldrealms65

    (@coldrealms65)


    Not sure how much of this you can help with as it is down to Divi, ACF, and you. (tested by deactivating all other plugins but those

    ON this test page: https://ncdcstaging.wpengine.com/alumnus/ you can see the results of a custom post type: alumni_list sorted as we want it.

    But here: https://ncdcstaging.wpengine.com/state/south-carolina/ you can see the same Divi template being applied to the “state” taxonomy but the order is by date…

    When I echo out the order and orderby values the page that works shows ASC and last_name (which is correct) but on the broken taxonomy pages the same echo shows DESC and nothing for the orderby

    I just don’t understand it as they use the same template and the code i use to set the sort fires on both pages…

    What the hell am I missing?

    Note: I have tested with every kind of sorting option and cannot get any of them to work. Including editing the DIVI blog.php file directly

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Not sure what to suggest here, but I have to believe it’s coming down to code and details coming from Divi more than anything. CPTUI itself isn’t going to be doing anything regarding queries, we’re just making sure the content types are registered as and when needed.

    Not sure what all settings may have been used already to order by last name, but I have to believe that that is failing to apply for the states, and that archive will need its own custom orderby set somehow.

    Thread Starter coldrealms65

    (@coldrealms65)

    I was thinking the same thing. either that or i’ll need to write my own loop just for those pages.

    I did try a few tweaks to attempt to target the state taxonomy but those failed. I also tried the “wp_set_object_terms(get_the_ID(), ‘last_name’, ‘state’, true);” but I don’t understand what I am even doing there.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Something similar to the code at https://developer.www.ads-software.com/reference/functions/is_tax/#comment-3736 could help with ordering.

    Regarding wp_set_object_terms() that’s used for adding terms to the post.

    So wp_set_object_terms(get_the_ID(), ‘last_name’, ‘state’, true); would essentially be creating a term of last_name in the state taxonomy.

    Thread Starter coldrealms65

    (@coldrealms65)

    Woot!!!

    add_action( ‘pre_get_posts’, function( $query) {
    if ( $query->is_tax( ‘state’ ) ) { // Replace with the name of the taxonomy you want to target
    $query->set( ‘orderby’, ‘last_name’ ); // change ‘6’ to the number of posts you want to appear
    $query->set(‘meta_key’, ‘last_name’);
    $query->set(‘order’, ‘ASC’);
    }

    } );

    Was the key

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Glad you got things working as needed. Let us know if you need anything else.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Unable to sort items in certain taxonomy’ is closed to new replies.