Order Articles Based on Category but by Custom Post Type

I have a page that is using a Custom Post Type called ‘Articles’.

I’m wondering how to query the content to order the ‘Articles’ on the frontend by Title in ASC, but the posting of ‘Articles’ on the frontend needs to be by a specific category and not modify any other post listings.

I tried developing this within the ‘functions.php’:

function alpha_order_classes( $query ) {
    if ( $query->is_post_type_archive('Articles') && $query->is_main_query() ) {
        $query->set( 'orderby', 'title' );
        $query->set( 'order', 'ASC' );

But I’m not seeing any results or any errors on the frontend. I would prefer to use a function within the functions.php file rather than manipulating the template file, if at all possible.

The template that needs to be modified is NOT the category.php template. Instead it uses the page-template.php and references the loop.php file.

Thank you.

Have you checked out the WordPress documentation on WP_Query() (https://codex.wordpress.org/Class_Reference/WP_Query)? Under parameters, you will find how to handle custom post types and taxonomies with WP_Query.

Yep, and I wound up modifying the array code to this:

<?php $args = array(
		'post_type' => 'html5-blank',
		'posts_per_page' => 10,
		'orderby' => 'title',
		'order' => 'ASC'

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.