Skip to content

Instantly share code, notes, and snippets.

@ashsaraga
Last active August 27, 2021 16:25
Show Gist options
  • Save ashsaraga/6e811b0355ca125d8131fdd2e11c56a3 to your computer and use it in GitHub Desktop.
Save ashsaraga/6e811b0355ca125d8131fdd2e11c56a3 to your computer and use it in GitHub Desktop.
Sorts any archive by any meta field.
<?php
$the_key = ''; // Field Name to sort on
$args = array( 'meta_key' => $the_key,
'orderby' => 'meta_value',
'order' => 'ASC'
);
global $wp_query;
query_posts(
array_merge(
$wp_query->query,
$args
)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment