function esc_display_event_schedule($atts) { // Set default attributes $atts = shortcode_atts( array( 'category' => '', // Optional category filter 'limit' => 5, // Default limit of events to show 'orderby' => 'date', // Default order by date 'order' => 'ASC', // Default order ASC ), $atts, 'event_schedule'); // Query for custom post type 'tcode_event' (adjust the slug if needed) $args = array( 'post_type' => 'tcode_event', // Make sure this is correct 'posts_per_page' => $atts['limit'], 'orderby' => $atts['orderby'], 'order' => $atts['order'], ); // If a category is passed, filter by category (make sure the taxonomy exists) if (!empty($atts['category'])) { $args['tax_query'] = array( array( 'taxonomy' => 'event_category', // Make sure the taxonomy is correct 'field' => 'slug', 'terms' => $atts['category'], 'operator' => 'IN', ) ); } // Run the query to get events $query = new WP_Query($args); // Debugging: Output the query results $output = '
';
    $output .= print_r($query, true);
    $output .= '
'; // If events exist, display them in the Event Schedule template format if ($query->have_posts()) { $output .= '
'; while ($query->have_posts()) { $query->the_post(); // Safely retrieve categories and handle WP_Error $terms = wp_get_post_terms(get_the_ID(), 'event_category', array('fields' => 'names')); // Check if terms is an array before imploding if (!is_wp_error($terms) && is_array($terms)) { $output .= '

Categories: ' . implode(', ', $terms) . '

'; } else { $output .= '

No categories found for this event.

'; } $output .= '
'; $output .= '
'; $output .= '

' . get_the_title() . '

'; $output .= '

' . get_the_date('F j, Y') . '

'; $output .= '
'; $output .= '
'; // Check if custom fields exist and display them if ($event_time = get_field('event_time')) { $output .= '

Event Time: ' . esc_html($event_time) . '

'; } if ($artist_name = get_field('artist_name')) { $output .= '

Artist: ' . esc_html($artist_name) . '

'; } // Display event excerpt if (has_excerpt()) { $output .= '

' . get_the_excerpt() . '

'; } // Link to event page (optional) $output .= 'View Event Details'; $output .= '
'; // .event-schedule-content $output .= '
'; // .event-schedule-item } $output .= '
'; // .event-schedule-container // Reset post data wp_reset_postdata(); } else { $output .= '

No events found.

'; } return $output; } المتحدثون 2024 - Saudi Retail Forum | Conference | Summit & Awards 2024
Reach us on WhatsApp
1