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.

How can I sort posts ascending by post title for a specific post type, but on a category archive template?

My schema involves a "video" custom post type and multiple subcategories of the aforementioned post type.

I am using the Custom Content Type Manager plugin.

How can I implement this?

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

You can use pre_get_posts to hook in and change the query.

The argument passed to pre_get_posts is the query object. It fires for every query, so you need to check some things first. Quick example (not-tested) -- change the order on only the video type's post type archive page.

<?php
add_action('pre_get_posts', 'wpse73991_change_order');
function wpse73991_change_order($q)
{
    if(
        is_admin() || // no admin area mods
        !$q->is_main_query() || // make sure we're modifying the main loop
        !$q->is_post_type_archive('videos') // is this the video archive? (you might need to change this)
    ) return; // bail, we're not where we want to be.

    // change the order
    $q->set('order', 'title');
}
share|improve this answer
add comment

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.