bep42
bep42

Reputation: 351

How to sort category posts alphabetically in WordPress?

Sorry about that but I can't figure out what's wrong with my code.
I am trying to sort my posts from category #3 alphabetically but I think I'm doing it wrong.

<?php
    $catquery = new WP_Query( 'cat=3' );
    while($catquery->have_posts()) : $catquery->the_post('&orderby=title&order=ASC');
?>

Upvotes: 1

Views: 1275

Answers (2)

Rp9
Rp9

Reputation: 1963

try sort from query itself

$args = [
            'order' => 'ASC',
            'orderby' => 'title',
        ];

        $query = new WP_Query($args);

Upvotes: 1

Dmitry Leiko
Dmitry Leiko

Reputation: 4382

Try this:

<?php

$args = array(
    'posts_per_page' => -1,
    'cat' => 3
    'orderby' => 'title',
    'order' => 'DESC'
);

    $catquery = new WP_Query($args);
    while($catquery->have_posts()) : $catquery->the_post();
?>

Hope help you.

Upvotes: 1

Related Questions