Viewing 15 replies - 1 through 15 (of 18 total)
  • joneiseman

    (@joneiseman)

    You could add this code snippet to limit it to a particular category:

    add_filter('em_calendar_template_args', function($args) {
    if ( !empty($_GET['category']) ) {
    $args['category'] = sanitize_text_field($_GET['category']);
    }
    return $args;
    });

    You can use the Code Snippets plugin to add this code snippet.

    Then you can use the following as the feed in order to limit it to the “online” category:

    https://www.gleanreport.com/events.ics?category=online

    • This reply was modified 8 months ago by joneiseman.
    Thread Starter gleanreport

    (@gleanreport)

    Thanks I have added that code to the Functions.php file.

    However, I am now just looking for the url for the text based RSS feed – the url provides a ics feed of events for a calendar instead

    joneiseman

    (@joneiseman)

    Try this:

    add_filter('em_rss_template_args', function($args) {
    if ( !empty($_GET['category']) ) {
    $args['category'] = sanitize_text_field($_GET['category']);
    }
    return $args;
    });

    Then add ?category=online to the URL to your RSS feed.

    For example:

    https://www.gleanreport.com/events/rss/?category=online

    • This reply was modified 8 months ago by joneiseman.
    • This reply was modified 8 months ago by joneiseman.
    Thread Starter gleanreport

    (@gleanreport)

    Thanks for that – unfortunately this still pulls all the events into the RSS feed, not just the online category events.

    I’ve tried playing with the URL and it still doesn’t work.

    Any ideas gratefully received!

    joneiseman

    (@joneiseman)

    It worked for me. I added the code snippet as follows:

    add_filter('em_rss_template_args', function($args) {
    if ( !empty($_GET['category']) ) {
    $args['category'] = sanitize_text_field($_GET['category']);
    }
    return $args;
    });

    Then I used the following URL and it restricted the events in the rss feed to those with the category club-event:

    https://mafw.org/events/feed/?category=club-event

    Thread Starter gleanreport

    (@gleanreport)

    Thanks @joneiseman, I really appreciate your help.

    I have tried adding the snippet in Code Snippets but it is still bringing the whole RSS feed not just the online category.

    This is the list of events the RSS should be bringing up and only the ones added in the last 3 days: https://www.gleanreport.com/online/

    I’ve tried:

    https://www.gleanreport.com/events/feed/?category=online

    and

    https://www.gleanreport.com/events/categories/online/feed/

    joneiseman

    (@joneiseman)

    Sorry to hear it didn’t work for you.

    joneiseman

    (@joneiseman)

    Looks like somehow the code snippet didn’t get activated.

    Thread Starter gleanreport

    (@gleanreport)

    Thanks @joneiseman

    Could it be because I have custom code in the feed-rss2 file, for example:

    do_action('rss2_head'); ?>
    <?php if('event' == get_post_type() ): ?>
    <?php
    $description_format = str_replace ( ">", ">", str_replace ( "<", "<", get_option ( 'dbem_rss_description_format' ) ) );
    $category = get_the_terms( get_the_id(), 'event-categories' ); //////find custom taxonomy category name
    foreach ( $category as $cat){
    $evcat = $cat->term_id;
    }

    $EM_Events = EM_Events::get( array('scope'=>'month', 'owner'=>false, 'category'=> $evcat) ); // this line pulls in JUST the specified category... and the SCOPE nextfortnight is my own custom scope, replace it with yours or a default I replaced with month/

    foreach ( $EM_Events as $EM_Event ) {

    $description = $EM_Event->output( get_option ( 'dbem_rss_description_format' ), "rss");
    $description = ent2ncr(convert_chars(strip_tags($description))); //Some RSS filtering
    $event_url = $EM_Event->output('#_EVENTURL');
    ?>
    <item>
    <title><?php echo $EM_Event->output( get_option('dbem_rss_title_format'), "rss" ); ?></title>
    <link><?php echo $event_url; ?></link>
    <guid><?php echo $event_url; ?></guid>
    <description><?php echo $description; ?></description>
    </item>
    <?php
    }
    ?>

    <?php else : ?>

    <?php while( have_posts()) : the_post(); ?>c

    Yes, that would explain why my code snippet didn’t work. I’m assuming that the following URL is calling feed-rss2: https://www.gleanreport.com/events/categories/online/feed/

    To get it to generate an RSS feed with just the events with the category online just change the following lines from this:

    		$category = get_the_terms( get_the_id(), 'event-categories' ); //////find custom taxonomy category name
    foreach ( $category as $cat){
    $evcat = $cat->term_id;
    }

    To this

           $evcat = 0;
    // If the current URL is https://www.gleanreport.com/events/categories/online/feed/
    // the $evcat will get set to "online"
    $url = $_SERVER['REQUEST_URI'];
    $parts = explode('/', $url);
    $filtered_parts = array_filter($parts);
    $final_parts = array_values($filtered_parts);
    if (count($final_parts) >= 2) {
    $evcat = $final_parts[count($final_parts) - 2];
    }

    The other potential problem I see is with the following code:

    <?php if('event' == get_post_type() ): ?>

    This assumes that $post is set before feed-rss2.php is called.

    • This reply was modified 7 months, 4 weeks ago by joneiseman.
    Plugin Author Marcus

    (@msykes)

    Hello, I was tackling this bug because with our new Archetypes feature, not all archetypes are included by default. They are now (or at least, will be in the upcoming update).

    However, in my tests using the URL of a specific category and trailing it with /feed will produce a proper RSS feed with just that category events.

    This should be working in the current update too, it’s triggered in the em_rss() function in events-manager.php, which would then trigger the templates/templates/rss.php template file.

    If you’re not overriding template files, I’m wondering if your issue may be cache-related? Do you have caching? Try clearing your cache.

    Thread Starter gleanreport

    (@gleanreport)

    Thanks @msykes, I really appreciate your help.

    I have tried clearing the cache, but it has not changed the “online” url feed.

    I’m wondering if the issue may be because the feed is limited to posts added in the last 3 days? This is the code in the functions.php that does this:

    <?php

    add_filter( 'em_events_build_sql_conditions', 'my_em_scope_conditions',1,2);
    function my_em_scope_conditions($conditions, $args){
    if( !empty($args['scope']) && $args['scope']=='newposts' ){
    $start_date = date('Y-m-d H:i:s',strtotime("-3 days", current_time('timestamp')));
    $conditions['scope'] = " ( event_date_modified >= '$start_date') OR ( event_date_created >= '$start_date')";
    }
    return $conditions;
    }

    add_filter( 'em_get_scopes','my_em_scopes',1,1);
    function my_em_scopes($scopes){
    $my_scopes = array(
    'newposts' => 'New Posts'
    );
    return $scopes + $my_scopes;
    }

    add_action('em_event_output_show_condition', 'my_em_new_event_output_show_condition', 1, 4);
    function my_em_new_event_output_show_condition($show, $condition, $full_match, $EM_Event){
    if( "is_newpost" == $condition ){
    $postdate = get_post_datetime($EM_Event->post_id)->format('Y-m-d');
    $threedaysago = date('Y-m-d', strtotime('-3 days', current_time('timestamp')));
    $show = strtotime($postdate) >= strtotime($threedaysago) ? true : false;
    }
    return $show;
    }

    Maybe this is overiding the template files?

    Plugin Author Marcus

    (@msykes)

    If you’re choosing that scope in your feed settings, then yes. If not, I don’t think so.

    I’d suggest removing all custom code first, see if it works, if it does then you know where to look.

    For example, the demo site works fine, showing only the events for that category:
    https://eventsmanager.site/events/categories/hiphop-2/feed/

    Thread Starter gleanreport

    (@gleanreport)

    Thanks so much @msykes

    I removed the functions.php file competely (which did nothing) but then cleared the cache – and the feeds worked (sort of)! The “wellington” RSS feed pulled every post from the wellington category all the way back to 2014 when the site began. The “online” RSS feed appeared to pull every post from when the “online” category began in October.

    Do you have any suggestions for tweaking the following code in the functions.php file so that only posts entered or modified in the last 3 days are pulled up in the two RSS feeds – while keeping only that category’s events in the appropriate feed?

    <?php

    add_filter( 'em_events_build_sql_conditions', 'my_em_scope_conditions',1,2);
    function my_em_scope_conditions($conditions, $args){
    if( !empty($args['scope']) && $args['scope']=='newposts' ){
    $start_date = date('Y-m-d H:i:s',strtotime("-3 days", current_time('timestamp')));
    $conditions['scope'] = " ( event_date_modified >= '$start_date') OR ( event_date_created >= '$start_date')";
    }
    return $conditions;
    }


    add_filter( 'em_get_scopes','my_em_scopes',1,1);
    function my_em_scopes($scopes){
    $my_scopes = array(
    'newposts' => 'New Posts'
    );
    return $scopes + $my_scopes;
    }

    add_action('em_event_output_show_condition', 'my_em_new_event_output_show_condition', 1, 4);
    function my_em_new_event_output_show_condition($show, $condition, $full_match, $EM_Event){
    if( "is_newpost" == $condition ){
    $postdate = get_post_datetime($EM_Event->post_id)->format('Y-m-d');
    $threedaysago = date('Y-m-d', strtotime('-3 days', current_time('timestamp')));
    $show = strtotime($postdate) >= strtotime($threedaysago) ? true : false;
    }
    return $show;
    }

    /**
    * Custom post type for Subscribe2
    */
    function custom_s2_post_types($types) {
    $types[] = 'event';
    return $types;
    }
    add_filter('s2_post_types', 'custom_s2_post_types');

    add_filter('s2_post_types','my_post_types');
    function my_taxonomy_types($taxonomies) {
    $taxonomies[] = 'event-categories';
    return $taxonomies;
    }
    add_filter('s2_taxonomies','my_taxonomy_types');

    Plugin Author Marcus

    (@msykes)

    Have you checked your Settings > Formatting > RSS settings? The scope should be your custom one, my guess is somewhere your scope isn’t adding the constraints, and therefore it defaults to ‘all’.

    It looks OK to me at a glance, it’d need testing (which I can’t do due to time constraints), but what you’d want to do as a first step is set a break to that you know for sure your conditions are overriding.

Viewing 15 replies - 1 through 15 (of 18 total)

You must be logged in to reply to this topic.