• I am working on a plugin and am trying to keep some history of a visitor’s landing page interest, for simplicity lets say I want to remember if they are interested in cats or dogs. I can store this in a cookie if they have cookies enabled, or in a session variable if not, (possibly the session variable is best because that should work for everyone).

    But then I thought – how about a global? If I set a global in my plugin, when does it get lost? When they change to a new page in the site? or does it remain while they navigate around? What if someone else comes to the site? would the global get changed for everyone or does everyone have their own instance of it running?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The global goes away at the end of each page computation. Even if it didn’t, it would only be global to the instance of the server that did that particular page. There is absolutely no guarantee that you will get the same server instance for all pages for any given user — in fact, you can pretty much bet that you won’t.

    So stick it in the session (which is fetched using cookies, but is often very short-lived) or in the DB. Without knowing more about what you are trying to achieve it’s hard to be more helpful.

    Thread Starter alchemistGM

    (@alchemistgm)

    okay, thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Understanding custom globals in wp’ is closed to new replies.