1

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');
?>
2
  • 1
    Ordering happens inside the query, not “in” an individual post. (What sense would it make to sort one post by anything? One single item has the same “order” any time anywhere, no matter what criterion you apply.)
    – 04FS
    Commented Dec 3, 2019 at 12:08
  • Thanks, sorry I'm a bit new in php :)
    – bep42
    Commented Dec 3, 2019 at 18:43

2 Answers 2

1

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.

1
  • thanks it works with some adjustments : 'cat' => 3, 'order' => 'ASC'
    – bep42
    Commented Dec 3, 2019 at 18:47
1

try sort from query itself

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

        $query = new WP_Query($args);

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.