I want to order my posts alphabetically but I don't know how I can do it with my code. This is my code.
<div class="row">
<div class="large-6 medium-12 small-12 columns">
<h3>Elektrotechniek</h3>
<?php query_posts('category_name=elektrotechniek');
if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="row">
<div class="opleiding-blok">
<div class="large-6 medium-6 small-12 columns">
<div class="opleiding-image"><?php the_post_thumbnail(); ?></div>
</div>
<div class="large-6 medium-6 small-12 columns no-padding-left">
<div class="opleiding-content">
<div class="opleiding-titel">
<h5><?php the_title(); ?></h5>
</div>
<div class="opleiding-knop">
<a href="<?php the_permalink() ?>" class="button-opleidingen groot" title="Lees verder">Meer Info...</a>
</div>
</div>
</div>
</div>
</div>
<?php endwhile;
endif;
wp_reset_query(); ?>
</div>
</div>
can somebody help me, Thank you
I want to order my posts alphabetically but I don't know how I can do it with my code. This is my code.
<div class="row">
<div class="large-6 medium-12 small-12 columns">
<h3>Elektrotechniek</h3>
<?php query_posts('category_name=elektrotechniek');
if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="row">
<div class="opleiding-blok">
<div class="large-6 medium-6 small-12 columns">
<div class="opleiding-image"><?php the_post_thumbnail(); ?></div>
</div>
<div class="large-6 medium-6 small-12 columns no-padding-left">
<div class="opleiding-content">
<div class="opleiding-titel">
<h5><?php the_title(); ?></h5>
</div>
<div class="opleiding-knop">
<a href="<?php the_permalink() ?>" class="button-opleidingen groot" title="Lees verder">Meer Info...</a>
</div>
</div>
</div>
</div>
</div>
<?php endwhile;
endif;
wp_reset_query(); ?>
</div>
</div>
can somebody help me, Thank you
Share Improve this question edited Nov 3, 2020 at 8:22 joelschout asked Nov 3, 2020 at 8:16 joelschoutjoelschout 11 bronze badge1 Answer
Reset to default 1Add both orderby
and order
query parameters.
Here is an excerpt of the PHP code you need:
$query_args = array(
"category_name" => "elektrotechniek",
"orderby" => "post_title",
"order" => "ASC"
);
Use post_title
in case you need to order your posts by title, or post_name
in case you prefer to order your posts by slug. Any other field of the wp_posts
table can be used to order the posts by.
If you don't add ASC
as the order
value, WordPress orders the posts in a descendant way.