Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@salcode
Created April 8, 2014 01:12
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 salcode/10079838 to your computer and use it in GitHub Desktop.
Save salcode/10079838 to your computer and use it in GitHub Desktop.
WordPress Burbs Sort Posts by Custom Meta Value
<?php
// short code to display by meta_key job_title
add_shortcode( 'burbs_sort_test', 'burbs_sort_test' );
function burbs_sort_test() {
global $post;
echo '<pre>';
$atts = array(
'post_type' => 'post',
'order' => 'ASC',
'orderby' => 'meta_value',
'meta_key' => 'job_title',
);
$wp_query = new WP_Query($atts);
while( $wp_query->have_posts() ) : $wp_query->the_post();
the_title();
echo ' -> ';
echo get_post_meta( $post->ID, 'job_title', true );
echo '<br>';
endwhile;
echo '</pre>';
wp_reset_query();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment