0

How can I add the order by date created to this function?

if ( !isset( $gmw['search_results']['custom_taxes'] ) )
    return;

$taxonomies = apply_filters( 
    'gmw_pt_results_taxonomies', 
    get_object_taxonomies( $post->post_type, 'names' ), 
    $gmw, 
    $post 
);

$output ='';

foreach ( $taxonomies as $tax ) {

    $terms = get_the_terms( $post->ID, $tax );

    if ( $terms && !is_wp_error( $terms ) ) {

        $termsArray = array();
        $the_tax = get_taxonomy( $tax );

        foreach ( $terms as $term ) {
            $termsArray[] = $term->name;
        }
1
  • 5
    Where do you have the terms' creation date from? It's not stored by default as far as I remember.
    – birgire
    Sep 29 '16 at 18:08
0

If you want to achieve that, then you need to add creation_date for each taxonomy, hooked with 'create_category' (or create_YOURTAXONOMYNAME) function.

lets say,for example, you add a new category :

add_action( "create_category", 'my_func123', 10, 2 ); 
function my_func123( $term_id, $tt_id){
    update_option('my_taxnm_date_'.$term_id, time());
}

then later, anytime, you will be able to get the creation date for each taxonomy id:

foreach ( $terms as $term ) {
   $termsArray[]['Name'] = $term->name;
   $termsArray[]['Date'] = get_option('my_taxnm_date_'.  $term->term_id) ;
}

now, you just have to sort the array, like: ksort($termsArray[]); and then you will have sorted array.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.