php - Wordpress: $categories as $category - sort by date -


i've got following code show categories , last post in category - using wordpress:

foreach( $categories $category ) { $category_link = sprintf(     '<a href="%1$s" alt="%2$s">%3$s</a>',     esc_url( get_category_link( $category->term_id ) ),     esc_attr( sprintf( __( 'view posts in %s', 'textdomain' ),     $category->name ) ),     esc_html( $category->name )                         );  global $post; $args = array( 'posts_per_page' => 1,  'category' => $category->term_id);  $myposts = get_posts( $args ); foreach ( $myposts $post ) : setup_postdata( $post );  $newpost="<a href=".get_the_permalink()."><b>".get_the_title()."</b></a> $newdate=get_the_date(); endforeach;  

right categories sorted alphabet.

is there way sort them date of last post?

i thought putting argument first line like:

 foreach( $categories $category sort ... ) 

but couldn't find way.

maybe can help?

thank help!

just found working code: get_categories order last post

you can sort records of $categories :

$categories = array('post_status'=>'publish','post_type' => 'test', 'orderby' =>  'date', 'order' => 'desc','paged' => $paged ); 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

.htaccess - ERR_TOO_MANY_REDIRECTS htaccess -