Skip to content

Instantly share code, notes, and snippets.

/Functions.php Secret

Created March 10, 2016 13:37
Show Gist options
  • Save anonymous/237edb9ccb8af05b9e27 to your computer and use it in GitHub Desktop.
Save anonymous/237edb9ccb8af05b9e27 to your computer and use it in GitHub Desktop.
Pre-get-post function to sort post by ACF date field.
<?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