Created
October 11, 2023 11:54
-
-
Save frikishaan/e5d67f42a32422163fb20da18ee46edc to your computer and use it in GitHub Desktop.
Sort Posts by meta value - Generate Press
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'generateblocks_query_loop_args', function( $query_args, $attributes ) { | |
// apply filter if loop has class: courses-grid | |
if (! is_admin() && ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'courses-grid' ) !== false) { | |
$query_args = array_merge( $query_args, array( | |
'meta_key' => 'sort_order', | |
'orderby' => 'meta_value', | |
'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