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?

1 Answer 1


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.

add_action('pre_get_posts', 'wpse73991_change_order');
function wpse73991_change_order($q)
        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');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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