Hi,
I have a field with pre-set values (a dropdown). Now in the front end I would like to create an overview with all posts under a chosen value.
I made one loop but that does not seems to order my posts correctly so certainly I am missing something..
My loop is doing this now:
[code]
Chosen preset value A
-Title + content of post
Chosen preset value B
-Title + content of post
Chosen preset value A
-Title + content of post
[/code]
I want it to do this:
[code]
Chosen preset value A
-Title + content of post
-Title + content of another post
-Title + content of another post
Chosen preset value B
…
…
etc
[/code]
My loop looks like this now:
[code]
$option = $_GET[“option”];
// query
$the_query = new WP_Query(array(
‘post_type’ => ‘post’,
‘posts_per_page’ => -1,
‘meta_key’ => ‘locatie’,
‘orderby’ => ‘meta_value_num’,
‘order’ => ‘DESC’
));
?>
<?php if( $the_query->have_posts() ): ?>
<?php while( $the_query->have_posts() ) : $the_query->the_post(); ?>
<h1><?php the_field(‘locatie’); ?></h1>
-
“>
<?php the_title(); ?>
<?php endwhile; ?>
<?php endif; ?>
[/code]
Any ideas?
Hi @vana
Meta_value_num is used to sort numeric meta value. This page should give you more idea about it: https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters.
Kindly use meta_value instead:
$the_query = new WP_Query(array(
'post_type' => 'post',
'posts_per_page' => -1,
'meta_key' => 'locatie',
'orderby' => 'meta_value',
'order' => 'DESC'
));
Hope this helps.