require_once plugin_dir_path(__FILE__) . 'copernico-importer.php'; function poll_copernico_events() { $now = current_time('Y-m-d H:i:s'); $args = array( 'post_type' => 'event', 'posts_per_page' => -1, 'meta_query' => array( array( 'key' => 'copernico_poll_start_time', 'compare' => 'EXISTS' ), array( 'key' => 'copernico_poll_stop_time', 'compare' => 'EXISTS' ) ) ); $events = get_posts($args); foreach ($events as $event) { $post_id = $event->ID; $start_time = get_field('copernico_poll_start_time', $post_id); $stop_time = get_field('copernico_poll_stop_time', $post_id); if ($start_time && $stop_time && $now >= $start_time && $now <= $stop_time) { error_log("📡 Running Copernico poll for event $post_id at $now"); $importer = new Copernico_Importer(); $importer->setPostId($post_id); $importer->getInfo(); $importer->getData(); } } }