Skip to content

Instantly share code, notes, and snippets.

@billerickson
Forked from anonymous/Functions.php
Last active March 10, 2016 13:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save billerickson/4e485f451e980a21b23f to your computer and use it in GitHub Desktop.
Save billerickson/4e485f451e980a21b23f 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 ) {
if( $query->is_main_query() && !is_admin() && ( $query->is_home() || $query->is_archive() ) ) {
$query->set('orderby', 'meta_value_num');
$query->set('meta_key', 'deadline');
$query->set('order', 'ASC');
}
}
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