1

I would like to order a list of post title alphabetically. I am using this specific query

// WP_Query arguments
$args = array(
    'category_name'     => 'reportage',
    'order'             => 'ASC',
    'orderby'           => 'title',
);

// The Query
$query = new WP_Query($args);

// The Loop
if ($query->have_posts()) {
    while ($query->have_posts()) {
        $query->the_post();
        echo '<ul><li style="float:left; width:100%;"><a href="'.get_the_permalink().'" style="color:#D34D3D">'.get_the_title().'</a></li></ul>';
    }
} else {
    // no posts found
}

// Restore original Post Data
wp_reset_postdata();

The query worked perfect until a certain point of the list where the order seems to be messed up.

Why the order doesn't work correctly for all the post title?

2

Try adding 'suppress_filters' => true to your query args. Maybe you have a plugin that modifies the queries.

You could also check if the posts out of order (the first one) is a sticky post. Sticky posts by default skip the order queue.

You can disable this by adding 'ignore_sticky_posts' => true to your query args.

  • Thank you for the reply. I added the string, however it doesn't work. I tried to deactivate CPO (Custom Post Order) in order to make the default order, without results. Any other ideas? – Stefano Dec 12 '16 at 15:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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