Home › Forums › Front-end Issues › Displaying taxonomy in shortcode loop
Please help – i am trying to display the cat ID as the class of the looped a tag so I can colour the background dependent on the category but I cannot get it to work. Any ideas where I am going wrong?
function upcomingEvents_shortcode() {
$today = date('Ymd');
$terms = get_field('eventcategory');
$upcomingeventsshortcode = new WP_Query(array(
'post_type' => 'event',
'posts_per_page' => 3,
'meta_key' => 'start',
'meta_query' => array(
array(
'key' => 'start',
'value' => $today,
'compare' => '>=',
'type' => 'DATETIME',
)),
'orderby' => 'meta_value',
'order' => 'ASC'
));
if($upcomingeventsshortcode->have_posts()) : while($upcomingeventsshortcode->have_posts()) : $upcomingeventsshortcode->the_post();
$color = get_field('colour', 'term_'.$term->term_id());
$upcomingEventsLink .= get_the_permalink();
$upcomingEventsTitle = get_the_title();
$upcomingEventsDate = get_field(start, false, false);
$upcomingEventsDay = date("j", strtotime($upcomingEventsDate));
$upcomingEventsMonth = date("M", strtotime($upcomingEventsDate));
$upcomingEventsOutput .= "
<div class='event-summary'>
<a class='event-summary__date t-center $color' href='$upcomingEventsLink'>
<span class='event-summary__month'>$upcomingEventsMonth</span>
<span class='event-summary__day'>$upcomingEventsDay</span>
</a>
<div class='event-summary__content'>
<span class='event-summary__title headline headline--tiny'><a href='$upcomingEventsLink'>$upcomingEventsTitle</a></span>
</div>
</div>";
endwhile; else: $upcomingEventsOutput .="nothing found.";
endif;
wp_reset_query();
return $upcomingEventsOutput . '<span class="events_shortcode__allevents"><a class="btn btn--blue" href="https://www.fyldecoastccgs.nhs.uk/news/upcoming-events/">View all upcoming events</a></span>';
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!
❓Ever wondered when and why ACF uses JSON instead of the database? Check out our summary of the most recent session of ACF Chat Friday for the answer, and make sure to register for the next session.
— Advanced Custom Fields (@wp_acf) February 23, 2023
👉 https://t.co/3UtvQbDwNmhttps://t.co/wfFEVcXVKc
© 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.