WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Use of Global Variables or Caching (3 posts)

  1. stefanstefanstefan
    Member
    Posted 4 years ago #

    Hi there,

    I'm trying to enhance the simplerssfetcher plugin and would like to build in some kind of caching, that for all users reloading the configured rss feed is done only daily or once a week.

    I tried to set some global variables, but whenever the page is reloaded (and so is the srssfetcher plugin) the global vars are empty.

    here some code:

    global $myVar;
    // Display srssfetcher messages
    function srssfetcher($rss = '', $num = 5, $list = true, $update = true, $linked  = true, $encode_utf8 = false) {
      if(isset($myVar)) { echo 'hi'; }
      else { echo 'ho'; $myVar = 'notItIsSet';}
    ...

    from my understanding it should output "ho" once and from then on "hi". but it always says "ho".
    I also tried to use the $GLOBALS variable. Same here: whenever I add a value it is gone if I reload the page.

    Can somebody please help me??
    Cheers
    Stefan

  2. Mohammad Jangda
    Member
    Posted 4 years ago #

    Global variables don't persist between page loads. Session variables do.

    However, for caching, you'll probably want to use the transients API. It's a simple way to cache data in the WordPress db.

  3. stefanstefanstefan
    Member
    Posted 4 years ago #

    Thanks batmoo

    works.

Topic Closed

This topic has been closed to new replies.

About this Topic