Is there a way to display only the legend value for the current day?

[ad_1]

Hey @no23h,

This is possible with a custom code snippet.

Add this code to your theme’s functions.php file:

add_shortcode('wpsbc-todays-legend', function ($atts, $content = null) {
    $events = wpsbc_get_events(array('calendar_id' => $atts['calendar_id'], 'date_day' => current_time('j'), 'date_month' => current_time('n'), 'date_year' => current_time('Y')));
    $legends = wpsbc_get_legend_items(array('calendar_id' => $atts['calendar_id']));
    if ($events && $events[0]->get('legend_item_id')) {
        foreach ($legends as $legend) {
            if ($legend->get('id') == $events[0]->get('legend_item_id')) {
                $legend_name = $legend->get_name();
            }
        }
    } else {
        foreach ($legends as $legend) {
            if ($legend->get('is_default')) {
                $legend_name = $legend->get_name();
            }
        }
    }

    return $legend_name;
});

This will create a shortcode called wpsbc-todays-legend

Add it anywhere on your page and pass the calendar ID as a parameter. It will return todays legend item from that calendar.

Eg.:

[wpsbc-todays-legend calendar_id="3"]

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer