gleanreport
Forum Replies Created
-
Thank you @msykes and @joneiseman – after a lot of testing (and trial and error) I have got this working! Really appreciate your help.
Thanks @msykes
Can you please tell me whether ‘New Posts’ in Settings > Formatting > RSS settings is my custom setting or a generic Events Manager setting?
Also – I have narrowed down the offending code to the following snippet in my functions.php file. If you have any suggestions for solving this issue (and I don’t expect you to spend time coding) I would really appreciate it:
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;
}Thanks @msykes!
I didn’t realise that RSS setting was there, that’s great. If I choose “New Posts”, how far back do those posts go? And does it include modified posts? Or is that scope simply drawing from my own custom code?
Kind regards,
Ruth
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');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?
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(); ?>cThanks @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
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 8 months ago by 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
Confirmed that it is working thank you so much! Is there a way to add posts that are modified in the past 3 days as well as those that have been created?
That appears to be working! Thank you so much. I’ll test it over the next few days and confirm.
Thanks for providing this code snippet. I have tried using the code but it does not bring up the *NEW* label before the text for events created within the last three days.
This conditional placeholder is still not working – any ideas when this might be fixed?
Apologies, this is a conditional placeholder not custom shortcode. Any chance that it will be fixed in the next update for Events Manager?
Actually, this is is bringing up every event as newposts! Is there a way to only bring up the ones that are -3 days old?