Okay
  Public Ticket #2195300
RSS Feed
Closed

Comments

  • Shane started the conversation

    Is there an RSS feed for events yet?

    If so what is the URL structure?

  •  894
    Zhivko replied

    Hi,

    No, sorry there's no built-in function at the moment.

    However you can write one in your theme functions.php file.

    Example:

    /**
     * Adds RSS to Stachethemes event calendar
     * RSS URL: [Website-URL]/?feed=stec-events
     */
    add_feed('stec-events', function() {
        ob_start();
        header('Content-Type: ' . feed_content_type('rss-http') . '; charset=' . get_option('blog_charset'), true);
        echo '<?xml version="1.0" encoding="' . get_option('blog_charset') . '"?' . '>';
        ?>
        <rss version="2.0"
             xmlns:content="http://purl.org/rss/1.0/modules/content/"
             xmlns:wfw="http://wellformedweb.org/CommentAPI/"
             xmlns:dc="http://purl.org/dc/elements/1.1/"
             xmlns:atom="http://www.w3.org/2005/Atom"
             xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
             xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
             >
            <channel>
                <title>Stachethemes Calendar Events</title>
                <atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" />
                <link><?php bloginfo_rss('url') ?></link>
                <description><?php bloginfo_rss('description') ?></description>
                <?php
                $events = \Stachethemes\Stec\Events::get_events();
                foreach ($events as $event) :
                    ?>
                    <item>
                        <title><?php echo $event->get_title(); ?></title>
                        <link><?php echo $event->get_permalink(); ?></link>
                        <description><![CDATA[<?php echo $event->get_description() ?>]]></description>
                        <guid isPermaLink="false"><?php echo $event->get_uid(); ?></guid>
                        <author><?php echo get_the_author_meta('display_name', $event->get_author()); ?></author>
                    </item>
                <?php endforeach; ?>
            </channel>
        </rss>
        <?php
        ob_get_flush();
    });

    Stachethemes Developer

  •  1
    Matt replied

    Hello, thank you for posting this example for an RSS feed! I'm trying to programmatically get a list of events in a date range (and also within selected categories). It looks like I should be able to modify this bit of code to pass "range_start" and "range_end" parameters, but I can't seem to make that work. Do you have an example of that?

    $events = \Stachethemes\Stec\Events::get_events();   
  •  894
    Zhivko replied

    Try this one:

    $start      = '2019-01-01 00:00:00';
    $end        = '2019-12-31 24:00:00';
    $range_tz   = 'UTC';
    $categories = [1, 2, 3]; // categories ids
    $params     = array(
        'tax_query' => array(
            array(
                'taxonomy' => 'stec_event_category',
                'field'    => 'term_id',
                'terms'    => $categories
            )
        )
    );
    $events = \Stachethemes\Stec\Events::get_events_between($start, $end, $range_tz, $params);
    



    Stachethemes Developer