fazarcon

order by views

Aug 30th, 2022
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. add_filter( 'generateblocks_query_loop_args', function( $query_args, $attributes ) {
  2. if ( ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'sort-view-count' ) !== false ) {
  3.  
  4. return array_merge( $query_args, array(
  5. 'meta_key' => 'post_views_count',
  6. 'orderby' => 'meta_value_num',
  7. 'order' => 'desc',
  8. ) );
  9. }
  10.  
  11. return $query_args;
  12. }, 10, 2 );
Advertisement
Add Comment
Please, Sign In to add comment