RSS feed by category
-
Thanks again for a wonderful plugin.
I am trying to create an RSS feed for one category of events.
The category name is “online” and the category ID is 9.
When I try this RSS feed it provides all of the events instead of just the online category: https://www.gleanreport.com/events/categories/online/feed/
Hoping someone can help.
The page I need help with: [log in to see the link]
-
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 1 month, 1 week ago by
joneiseman.
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
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 1 month ago by
joneiseman.
-
This reply was modified 1 month ago by
joneiseman.
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!
-
This reply was modified 1 month ago by
gleanreport.
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:
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
Sorry to hear it didn’t work for you.
Looks like somehow the code snippet didn’t get activated.
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(); ?>cYes, 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 1 month ago by
joneiseman.
-
This reply was modified 1 month, 1 week ago by
You must be logged in to reply to this topic.