function itinerary_shortcode_output($is_ajax = false) {
ob_start();
if (!$is_ajax && empty($_POST)) {
return '
Please complete all required fields to generate your itinerary.
';
}
$location_term = get_term_by('slug', $selected_location, 'location');
if (!$location_term) {
return 'Invalid location selected. Please try again.
';
}
$output = '';
$output .= '
Your Personalized Itinerary
';
$output .= '
Explore ' . esc_html($location_term->name) . ' based on your interests and time.
';
$shown_ids = [];
for ($day = 1; $day <= $selected_days; $day++) {
$output .= '
Day ' . $day . '
';
$output .= '
';
$args_first_spot = [
'post_type' => 'travel_spot',
'posts_per_page' => 1,
'orderby' => 'meta_value_num',
'meta_key' => 'popularity',
'order' => 'DESC',
'post__not_in' => $shown_ids,
'meta_query' => [
'relation' => 'OR',
['key' => 'exclude_from_daywise', 'compare' => 'NOT EXISTS'],
['key' => 'exclude_from_daywise', 'value' => '0', 'compare' => '=']
],
'tax_query' => [
['taxonomy' => 'location', 'field' => 'slug', 'terms' => [$selected_location]],
['taxonomy' => 'interest_type', 'field' => 'slug', 'terms' => $selected_interest, 'operator' => 'IN']
]
];
$query_first_spot = new WP_Query($args_first_spot);
if ($query_first_spot->have_posts()) {
while ($query_first_spot->have_posts()) {
$query_first_spot->the_post();
$shown_ids[] = get_the_ID();
$output .= '
' . get_the_title() . '
';
$visiting_hours = get_field('visiting_duration');
if ($visiting_hours) {
$output .= '
' . esc_html($visiting_hours) . ' Hours
';
}
if (has_post_thumbnail()) {
$output .= '
' . get_the_post_thumbnail(get_the_ID(), 'full') . '
';
}
$output .= '
' . apply_filters('the_content', get_the_content()) . '
';
$output .= '
';
$related_spots = get_field('nearby');
if ($related_spots) {
foreach ($related_spots as $related_spot) {
if (!in_array($related_spot->ID, $shown_ids)) {
$shown_ids[] = $related_spot->ID;
$output .= '
' . get_the_title($related_spot->ID) . '
';
$related_visiting_hours = get_field('visiting_duration', $related_spot->ID);
if ($related_visiting_hours) {
$output .= '
' . esc_html($related_visiting_hours) . ' Hours
';
}
if (has_post_thumbnail($related_spot->ID)) {
$output .= '
' . get_the_post_thumbnail($related_spot->ID, 'full') . '
';
}
$related_post_content = get_post_field('post_content', $related_spot->ID);
$output .= '
' . apply_filters('the_content', $related_post_content) . '
';
$output .= '
';
}
}
}
}
wp_reset_postdata();
}
}
// Additional suggestions (excluded from daywise)
$suggested_args = [
'post_type' => 'travel_spot',
'posts_per_page' => -1,
'orderby' => 'meta_value_num',
'meta_key' => 'popularity',
'post__not_in' => $shown_ids,
'meta_query' => [
['key' => 'exclude_from_daywise', 'value' => '1', 'compare' => '=']
],
'tax_query' => [
['taxonomy' => 'location', 'field' => 'slug', 'terms' => $selected_location],
['taxonomy' => 'interest_type', 'field' => 'slug', 'terms' => $selected_interest]
]
];
$suggested_query = new WP_Query($suggested_args);
if ($suggested_query->have_posts()) {
$output .= '
Other Popular Things To Do As Per Your Interest
';
$output .= '
';
while ($suggested_query->have_posts()) {
$suggested_query->the_post();
$output .= '
' . get_the_title() . '
';
if (has_post_thumbnail()) {
$output .= '
' . get_the_post_thumbnail(get_the_ID(), 'full') . '
';
}
$output .= '
' . apply_filters('the_content', get_the_content()) . '
';
}
$output .= '
';
wp_reset_postdata();
}
$output .= '
'; // Close .itinerary-wrapper
// Inline styles
$output .= <<