Latest Post

How to search order by date in Wordpress

How to search order by date in Wordpress

How to search order by date in Wordpress


This code use for Search order by date

<?php
function my_search_query( $query ) {
// not an admin page and is the main query
if ( !is_admin() && $query->is_main_query() ) {
if ( is_search() ) {
$query->set( 'orderby', 'date' );
}
}
}

add_action( 'pre_get_posts', 'my_search_query' );
?>

No comments