Support

Account

Home Forums Front-end Issues Displaying taxonomy in shortcode loop

Helping

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>';
  • add

    
    global $post;
    

    to the top of your function.

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Displaying taxonomy in shortcode loop’ is closed to new replies.