Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

uritz on "Run a function only once - share variable across templates PHP"

$
0
0

I have a function (say call_api()) which reaches out to API and stores value in a variable which I then want to share across templates. I have tried a number of ways :

1) Using Session Variable and sharing the variable, but the function is called more than once.

2) Using static variable to run function only once.

Now, I want the function to run once when user loads the website, and store the value in a function which is stored in a variable which can be shared across various templates.

I have done extensive Google Search but was unable to come up with a solution. Can anyone please point me to the right direction ?


Viewing all articles
Browse latest Browse all 8245

Trending Articles