Hi,
Sorry I searched so much but got no answer in the www. I need to do the following (simplified):
- Define a variable with init value (e.g. 500)
- Make a calculation each day and alter the variable (eg. add 100)
- Display that variable in the frontend in elementor
It seems so easy, but in detail I struggle a lot. My idea was to a define a global variable in functions.php, add a cron job with calls a function each day in functions.php. Then add a shortcode to a function that returns the global variable and insert that shortcode into elementor. All works but not the alter of the variable. I miss something fundamental I think, as I am a newbie…
global $clients;
$clients = 500;
function cron_update() {
global $clients;
$clients += 100;
}
function get_clients() {
global $clients;
return $clients;
}
add_shortcode(‘GETCLIENTS’, ‘get_clients’);
I always get 500 as a result. Also after several cron jobs. I think the functions.php is called on each pageload so the init of the var is overwritten each time. How can I avoid that?
I also tried:
if (!isset($clients)){
global $clients;
$clients = 500;
}
but it seems also that it does it on each reload. So how can I define real global variables which stays intact?
I tried with GLOBALS but also no success…
Thank you,
Chris