• Resolved SmedleyButer

    (@smedleybuter)


    I was not understanding why my RSS didn’t update, after much wailing and gnashing of teeth I believe I have fixed this to a degree by editing wp-includes/feed.php.

    I changed this:

    $feed->set_cache_duration( apply_filters( ‘wp_feed_cache_transient_lifetime’, 12 * HOUR_IN_SECONDS, $url ) );

    To this:

    $feed->set_cache_duration( apply_filters( ‘wp_feed_cache_transient_lifetime’, 1 * HOUR_IN_SECONDS, $url ) );

    When it was changed the news did indeed refresh at least once and I believe I have set this to refresh once an hour. This is hard to test as an hour is a long time and sometimes there are gaps in the time that the RSS feeds themselves update.

    Say for instance I want this to in 30 minutes what would this look like? I’m looking for the proper way to enter the hours, minutes and seconds.

    Thanks for any insight you may provide this seems like the last step. I’m trying to get the RSS feed in a news forum to update more frequently as users are news junkies and once every 12 hours just isn’t fast enough for them to follow current events.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz

    (@bcworkz)

    Sorry for the slow response, I’ve been away.

    The parameter can resolve to any integer representing your desired time in seconds. For 30 minutes, the parameter could be 30*60 or 1800.

    However, you must never directly alter core files this way. You should learn how to use the filters provided, such as the one in your example: ‘wp_feed_cache_transient_lifetime’.

    There’s several places you can place code to hook filters, the functions.php file of your theme, or preferably a child theme, or a simple plugin. It’s good practice to create a site specific plugin to contain all such little hacks as this.

    Your hook code in this case would look like this:

    add_filter('wp_feed_cache_transient_lifetime', 'sb_feed_time', 10, 2 );
    function sb_feed_time( $time, $url ){
       return 1800;
    }

    This example collects the passed parameters, but ignores them. The parameters could be used to, for example, extend the cache time by 30% for particular URLs only.

    Thread Starter SmedleyButer

    (@smedleybuter)

    Thanks so much bcworks!

    I use that filter to speed up the refresh rates of the RSS and news feeds on my main site. The reason I was editing the core files is that I was (and still am 🙂 testing feeds on multiple themes on a development site. This allowed me to test many different themes without editing each.

    The development sites are transient. My coding and wordpress knowledge are still choppy to say the least. If I do this for testing (mind you I’m not holding your feet to the fire I know things don’t always go as they should even for the best of us 🙂 Will using the filter make them behave differently or am i ok with one size fits all for testing purposes.

    And thanks for the proper notation! I asked elsewhere, this information was treated as a national defense secret and I was soundly pelted with capital letters 🙂

    Moderator bcworkz

    (@bcworkz)

    😀 Withholding trade “secrets” in an open source community is… is… aw nuts, is so ridiculous I can’t even properly articulate my thoughts!

    In this particular case, there is absolutely no difference between altering the core file with a new number or doing so via a filter. In other cases, it depends on how you alter the core code and if a filter or action is available.

    There is no problem altering core files on a temporary basis as part of your development process, but it is improper as a permanent solution. If you do share such alterations in a public forum such as this, it’s a good idea to clarify your intent so no one is led to believe altering core files is a proper solution.

    You are free to do what you like on your own site of course, but altering core files in some cases can lead to frustration if there turns out to be no filter or action to hook to do as you need. Better to use filters as needed from the start to ensure the chosen approach is viable. You can avoid multiple edits in various themes by adding filters from a single common plugin that is applied regardless of which theme you happen to be testing. Filters work equally well when added from a plugin instead of a theme.

    Thread Starter SmedleyButer

    (@smedleybuter)

    Thanks bcworkz The info you gave me was great about the coding and also good about the “trade secrets” I’m new enough to WP so I wasn’t sure if I was committing some sort of breach of etiquette.

    I went to the WordPress section on a particular “Answer Site” and found it to be an extremely hostile environment to ask a question in. Part of the first response was: “You did what?? NEVER edit any core files or a theme/plugin that you are not the author of. ” In light of what I had seen here and elsewhere I thought the idea of never editing a theme or plugin you didn’t author yourself ludicrous.

    I think I’ll just stick with right here and hang out with the non anger management folks for technical questions in the future.:)

    Thanks again for the help on both counts!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘editing feed.php’ is closed to new replies.