Skip to content

Instantly share code, notes, and snippets.

@thisbit
Forked from codysmith44/gb-query-filter.php
Last active July 24, 2022 18:55
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 thisbit/9907105ab7df17f4362ac90706d37d49 to your computer and use it in GitHub Desktop.
Save thisbit/9907105ab7df17f4362ac90706d37d49 to your computer and use it in GitHub Desktop.
<?php
// GenerateBlocks variant of pre_get_posts for the query block
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