Home › Forums › Front-end Issues › Query for each custom taxonomy in menu order
Hello,
I’m trying to list event dates sorted by date asc and grouped by custom taxonomy.
The result should be something like:
TAXONOMY_1_NAME / TAXONOMY_1_DESC
06.02.2016 ….
20.02.2016 …
TAXONOMY_2_NAME / TAXONOMY_2_DESC
13.02.2016 ….
24.02.2016 …
My code is:
<ul id="events">
<?php
$args = array( 'post_type' => 'termine',
'posts_per_page' => 100,
'orderby' => 'meta_value',
'order' => 'ASC',
'meta_key' => 'event_date' );
$query = new WP_Query( $args );
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
$meta_date = get_field('event_date');
$date = date("d.m.Y", strtotime($meta_date));
$city = get_field('event_city');
$location = get_field('event-location');
$title = get_field('event_title');
$month = date("n", strtotime($meta_date));
$this_month = $monate[$month];
$description = get_field('event_dec');
$link_url = get_field('event_link_url');
$link_text = get_field('event_link_text');
if (empty($link_text)) {
$link_text = 'Link';
}
echo '<li>';
echo '<h3>'.$meta_date.' '.$city.', '.$title.'</h3>';
echo $description;
if (!empty($link_url)) {
echo '<a href="'.$link_url.'">'.$link_text.'</a>';
}
echo '</li>';
}
} else {
echo 'Keine Termine vorhanden.';
}
// Restore original Post Data
wp_reset_postdata();
?>
</ul>
How can I modify this query to get the event dates as described above?
Best.
P.
So if I understand correctly you want to order the posts by terms and then by date. There isn’t a way to order posts by term, you can read about this here and in the other urls that this links to. http://wordpress.stackexchange.com/questions/87639/wp-query-orderby-taxonomy-term-value-numeric
The easiest way to accomplish the is to get the terms and then do a new query based with that includes a tax_query for each term.
http://codex.wordpress.org/Function_Reference/get_terms
http://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
Are you building WordPress sites with ACF and @BeaverBuilder, and wanted to use your ACF Blocks in both the block editor and Beaver Builder?
— Advanced Custom Fields (@wp_acf) May 10, 2023
The BB team recently added support for using ACF Blocks in Beaver Builder. Check it out 👇https://t.co/UalEIa5aQi
© 2023 Advanced Custom Fields.
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.