// Add the printable schedule shortcode function printable_schedule_shortcode($atts) { // Fetch the sessions dynamically $args = array( 'post_type' => 'your_custom_post_type', // Replace with your custom post type for sessions/events 'posts_per_page' => -1, // Retrieve all sessions 'orderby' => 'meta_value', // Order by session date 'order' => 'ASC', // Ascending order (earliest session first) 'meta_key' => 'session_date', // Custom field for session date 'meta_query' => array( array( 'key' => 'session_date', // Custom field for session date 'compare' => 'EXISTS', // Ensure the field exists ), ), ); // Create the query $query = new WP_Query($args); $sessions = []; // If there are posts, process them if ($query->have_posts()) { while ($query->have_posts()) { $query->the_post(); // Fetch session details from custom fields $date = get_post_meta(get_the_ID(), 'session_date', true); // Custom field for session date $time = get_post_meta(get_the_ID(), 'session_time', true); // Custom field for session time $title = get_the_title(); // Title of the session $presenter = get_post_meta(get_the_ID(), 'session_presenter', true); // Custom field for session presenter // Add the session data to the sessions array $sessions[] = [ 'date' => $date, 'time' => $time, 'title' => $title, 'presenter' => $presenter, ]; } } // Reset post data wp_reset_postdata(); // Start building the output for the printable schedule $output = '
No sessions found.
'; } $output .= '