Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save propertyhive/ef68131ec9587e440bb01ceb10384e44 to your computer and use it in GitHub Desktop.

Select an option

Save propertyhive/ef68131ec9587e440bb01ceb10384e44 to your computer and use it in GitHub Desktop.
Put offices in a specific order
add_action( 'pre_get_posts', function( $query ) {
if ( is_admin() || ! $query->is_main_query() ) {
return;
}
// Adjust this condition if the plugin uses a shortcode/custom query.
if ( $query->get( 'post_type' ) !== 'office' && ! is_post_type_archive( 'office' ) ) {
return;
}
// LIST YOUR OFFICE IDS HERE IN THE ORDER YOU WANT
$office_order = array(
123,
456,
789,
321,
);
$query->set( 'post_type', 'office' );
$query->set( 'post__in', $office_order );
$query->set( 'orderby', 'post__in' );
$query->set( 'posts_per_page', -1 );
}, 99 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment