Hi !
I am struggling to show the two custom fields along with the post title. Post title shows but not the "custom_field_1" nor the "custom_field_2". Any idea why ? The query works fine (showing terms grouped by a custom field value "date" and ordered by name in "DESC").
The code :
<?php
// get the terms, ordered by name
// https://developer.wordpress.org/reference/functions/get_terms/
// https://developer.wordpress.org/reference/classes/wp_term_query/__construct/
$taxonomy = 'date-exposition';
$tax_terms = get_terms(
array(
'taxonomy' => $taxonomy,
'hide_empty' => false, // change to true if you don't want empty terms
'orderby' => 'name',
'order' => 'DESC',
'fields' => 'names', // return the term names only
)
);
foreach($tax_terms as $tax_term) { // loop through the terms
echo '<h2>' . $tax_term . '</h2>'; // echo the term name as a h2
$term_posts = get_posts( // find posts with the correct term
array(
'no_found_rows' => true, // for performance
'ignore_sticky_posts' => true, // for performance
'post_type' => 'exposition',
'posts_per_page' => -1, // return all results
'tax_query' => array( // https://developer.wordpress.org/reference/classes/wp_tax_query/
array(
'taxonomy' => $taxonomy,
'field' => 'name',
'terms' => array( $tax_term )
)
),
'fields' => 'ids', // return the post IDs only
)
);
echo '<ul class="fm-expo-list">'; // open bullet list
foreach ($term_posts as $term_post_id) { // loop through posts
$post_title = get_the_title($term_post_id); // get post title
$post_permalink = get_the_permalink($term_post_id); // get post link
$custom_field_1 = rwmb_get_value($fm_expo_city); // get custom post 1
$custom_field_2 = rwmb_get_value($fm_expo_year); // get custom post 2
echo
'<li>
<div class="fm-expo-line">
<span class="fm-expo-title">' . $post_title . '</span>
<span class="fm-expo-city">' . $custom_field_1 . '</span>
<span class="fm-expo-year">' . $custom_field_2 . '</span>
</div>
</li>';
}
echo '</ul>'; // close bullet list
}
?>