Created
August 9, 2015 04:43
-
-
Save hothanhan/ee065695c175ee6c9e09 to your computer and use it in GitHub Desktop.
get post order by date wordpress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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