Skip to content

Instantly share code, notes, and snippets.

@hothanhan
Created August 9, 2015 04:43
Show Gist options
  • Save hothanhan/ee065695c175ee6c9e09 to your computer and use it in GitHub Desktop.
Save hothanhan/ee065695c175ee6c9e09 to your computer and use it in GitHub Desktop.
get post order by date wordpress
Place code into theme functions.php or package into a plugin.
/**
* Sets up order post by date.
*
* @since 1.0.0
*/
function theworld_alter_query ( $query )
{
if ( $query -> is_main_query () && ( $query -> is_home () || $query -> is_search () || $query -> is_archive () ) )
{
$query -> set ( 'orderby' , 'date' );
$query -> set ( 'order' , 'desc' );
}
}
add_action ( 'pre_get_posts' , 'theworld_alter_query' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment