Created
April 8, 2014 01:12
-
-
Save salcode/10079838 to your computer and use it in GitHub Desktop.
WordPress Burbs Sort Posts by Custom Meta Value
This file contains hidden or 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 | |
// 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