Skip to content

Instantly share code, notes, and snippets.

@codysmith44
Last active July 24, 2022 18:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save codysmith44/a072cdef9f87d68494bac7d900c8fe5d to your computer and use it in GitHub Desktop.
Save codysmith44/a072cdef9f87d68494bac7d900c8fe5d to your computer and use it in GitHub Desktop.
<?php
add_filter( 'generateblocks_query_loop_args', function( $query_args, $attributes ) {
if ( ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'custom-grid-class' ) !== false ) {
$query_args['meta_key'] = 'field_name';
$query_args['orderby'] = 'meta_value'; // better for strings
// $query_args['orderby'] = 'meta_value_num'; // better for numbers
$query_args['order'] = 'ASC';
}
return $query_args;
}, 10, 2 );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment