-
-
Save anonymous/237edb9ccb8af05b9e27 to your computer and use it in GitHub Desktop.
Pre-get-post function to sort post by ACF date field.
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
<?php | |
function register_my_menus() { | |
register_nav_menus( | |
array( | |
'header-menu' => __( 'Header Menu' ), | |
'extra-menu' => __( 'Extra Menu' ) | |
) | |
); | |
} | |
add_action( 'init', 'register_my_menus' ); | |
function my_pre_get_posts( $query ) { | |
// do not modify queries in the admin | |
if( $query->is_main_query() && !is_admin() ) { | |
return $query; | |
} | |
// trier par date de deadline | |
else | |
{ | |
$query->set('orderby', 'meta_value_num'); | |
$query->set('meta_key', 'deadline'); | |
$query->set('order', 'ASC'); | |
} | |
// return | |
return $query; | |
} | |
add_action('pre_get_posts', 'my_pre_get_posts'); | |
?> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment