Trying to get the order of my custom query to display by Date created. Is this even possible with this query? Can you do a custom order? thanks for the help

<?php

$faq_cat_terms = get_terms( 'faq-cat' );


foreach ( $faq_cat_terms as $faq_cat ) {
    $faq_cat_query = new WP_Query( array(
        'orderby' => 'date',
        'post_type' => 'faq',
        'tax_query' => array(
            array(
                'taxonomy' => 'faq-cat',
                'field' => 'slug',
                'terms' => array( $faq_cat->slug ),
                'operator' => 'IN'
            )
        )
    ) );
    ?>

1 Answer
1

Maybe you just need to add:

'order'   => 'DESC', //or ASC

depending on which order you want them to be.

The title of your question sounds like you are trying to order taxonomy terms by their creation date which is not possible, but you can work around it by using the ID.

For example:

 $terms = get_terms( 'YOUR_TAX_TERM', $args );

Since taxonomy term IDs are created incrementally if you sort by ID you are sorting them in the order that they were created:

$args = array(
    'orderby'    => 'ID', 
    'order'      => 'DESC',
);

While not technically ordering by the date, this will accomplish essentially the same thing.

Leave a Reply

Your email address will not be published. Required fields are marked *