How to implement a counter that adds value once a day to WordPress?
1 answer
The following code should be added to the function.php theme file:
if ( ! wp_next_scheduled( 'my_task_hook' ) ) { wp_schedule_event( time(), 'daily', 'my_task_hook' ); }
function my_task_function() { $counter = get_option('my_counter', 0); $counter++; update_option('my_counter', $counter); // использовать $counter } add_action( 'my_task_hook', 'my_task_function' ); and use the $ counter variable where the comment is, or read it in the right place in the code with get_option, as in the example.
|
wordpress? - MichaelPak