Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have created a custom post type to display churches in Europe. I used a tutorial to make it filterable and everything on my site works as normal.

How would I organize the posts by country, instead of by title?

$loop = new WP_Query(
    array(
        'post_type' => 'europe',
        'posts_per_page' => -1,
        'orderby' => 'title',
        'order' => 'asc'
    )
);
$count = 0;
share|improve this question

1 Answer 1

I am assuming that 'country' is a custom meta field. In that case, you need this (very much like one of the examples in the Codex):

$loop = new WP_Query( 
    array ( 
        'post_type' => 'europe', 
        'posts_per_page' => -1,
        'orderby' => 'meta_value', 
        'meta_key' => 'country' 
        'order' => 'asc'
    ) 
);
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.