/** * GeneratePress child theme functions and definitions. * * Add your custom PHP in this file. * Only edit this file if you have direct access to it on your server (to fix errors if they happen). */ //PARA CUSTOMIZAR LA RESPUESTA function get_events_festival( $data ) { $args = array( 'post_type' => 'events', 'posts_per_page' => 8, 'meta_key' => 'fecha', 'orderby' => 'meta_value_num', 'order' => 'ASC', 'tax_query' => array( array( 'taxonomy' => 'tipo', 'field' => 'slug', 'terms' => 'festivals', ) ) ); $query = new WP_Query( $args ); $filter_posts = []; if ($query->have_posts()) { $posts = $query->posts; foreach ($posts as &$post) { $post_id = apply_filters('wpml_object_id', $post->ID, 'events', true); $post_data = get_post($post_id); $endDate = get_post_meta($post_data->ID, 'fecha1__end_date', true); $startDate = get_post_meta($post_data->ID, 'fecha1', true); $fecha_comparar = !empty($endDate) ? $endDate : $startDate; if($fecha_comparar >= time()){ $filtered_post = array( 'ID' => $post_data->ID, 'post_title' => $post_data->post_title, 'fecha' => $startDate, 'endDate' => $endDate, "hora" => get_post_meta($post_data->ID, 'hora', true), "fecha_y_hora" => get_post_meta($post_data->ID, 'fecha_y_hora', true), "p_entrada" => get_post_meta($post_data->ID, 'p_entrada', true), "p_vip" => get_post_meta($post_data->ID, 'p_vip', true), 'mandanga' => get_post_meta($post_data->ID, 'mandanga', true), 'descripcion' => get_post_meta($post_data->ID, 'descripcion', true), 'url_tiquets' => get_post_meta($post_data->ID, 'url_tiquets', true), 'link_carta' => get_post_meta($post_data->ID, 'link_carta', true), 'featured_image' => get_the_post_thumbnail_url($post_data->ID, 'full'), ); $filter_posts[] = $filtered_post; } } echo json_encode( $filter_posts ); } else { echo json_encode( [] ); } } add_action( 'rest_api_init', function () { register_rest_route( 'my', '/events-festival/', array( 'methods' => 'GET', 'callback' => 'get_events_festival', ) ); } ); function get_events_festes( $data ) { $args = array( 'post_type' => 'events', 'posts_per_page' => 8, 'meta_key' => 'fecha1', 'orderby' => 'meta_value_num', 'order' => 'ASC', 'meta_query' => array( array( 'key' => 'fecha1', 'value' => time(), 'type' => 'NUMERIC', 'compare' => '>' ) ) ); $query = new WP_Query( $args ); $filter_posts = []; if ($query->have_posts()) { $posts = $query->posts; foreach ($posts as &$post) { $post_id = apply_filters('wpml_object_id', $post->ID, 'events', true); $post_data = get_post($post_id); $fecha1_raw = get_post_meta($post_data->ID, 'fecha1', true); if (is_string($fecha1_raw)) { $fecha1_data = json_decode($fecha1_raw, true); if (json_last_error() !== JSON_ERROR_NONE) { $fecha1_data = maybe_unserialize($fecha1_raw); } } else { $fecha1_data = $fecha1_raw; } // Crear un nuevo objeto con solo los campos que quieras devolver $filtered_post = array( 'ID' => $post_data->ID, 'post_title' => $post_data->post_title, 'fecha' => get_post_meta($post_data->ID, 'fecha1', true), "hora" => get_post_meta($post_data->ID, 'hora', true), "fecha_y_hora" => get_post_meta($post_data->ID, 'fecha_y_hora', true), "p_entrada" => get_post_meta($post_data->ID, 'p_entrada', true), "p_vip" => get_post_meta($post_data->ID, 'p_vip', true), 'mandanga' => get_post_meta($post_data->ID, 'mandanga', true), 'descripcion' => get_post_meta($post_data->ID, 'descripcion', true), 'url_tiquets' => get_post_meta($post_data->ID, 'url_tiquets', true), 'link_carta' => get_post_meta($post_data->ID, 'link_carta', true), 'featured_image' => get_the_post_thumbnail_url($post_data->ID, 'full'), ); $filter_posts[] = $filtered_post; } echo json_encode( $filter_posts ); } else { echo json_encode( [] ); } } add_action( 'rest_api_init', function () { register_rest_route( 'my', '/events-festes/', array( 'methods' => 'GET', 'callback' => 'get_events_festes', ) ); } ); // Función para generar el grid de imágenes con botones de CTA function generar_grid_imagenes() { // Obtenemos las imágenes y los enlaces de los campos personalizados $vip = get_post_meta(get_the_ID(), 'vip', true); $vip2 = get_post_meta(get_the_ID(), 'vip2', true); $camping = get_post_meta(get_the_ID(), 'camping', true); $bus = get_post_meta(get_the_ID(), 'bus', true); $line_up = get_post_meta(get_the_ID(), 'line_up', true); $carta = get_post_meta(get_the_ID(), 'carta', true); // Obtenemos los enlaces para los botones $url_tiquets = get_post_meta(get_the_ID(), 'url_tiquets', true); $link_carta = get_post_meta(get_the_ID(), 'link_carta', true); // Creamos un array con las imágenes que vamos a mostrar $imagenes = array(); if (!empty($vip)) { $imagenes[] = array('image' => $vip, 'cta' => 'ENTRADA VIP', 'link' => $url_tiquets); } if (!empty($vip2)) { $imagenes[] = array('image' => $vip2, 'cta' => 'ENTRADA VIP 2', 'link' => $url_tiquets); } if (!empty($camping)) { $imagenes[] = array('image' => $camping, 'cta' => 'CAMPING', 'link' => $url_tiquets); } if (!empty($bus)) { $imagenes[] = array('image' => $bus, 'cta' => 'BUS', 'link' => $url_tiquets); } if (!empty($line_up)) { $imagenes[] = array('image' => $line_up, 'cta' => 'COMPRAR ENTRADAS', 'link' => $url_tiquets); } if (!empty($carta)) { $imagenes[] = array('image' => $carta, 'cta' => 'MENÚ ESPECIAL', 'link' => $link_carta); } // Comienza el HTML del grid $output = '
'; // Verificamos si hay imágenes para mostrar if (count($imagenes) > 0) { foreach ($imagenes as $index => $item) { // Creamos una fila de 3 imágenes if ($index % 3 == 0 && $index > 0) { $output .= '
'; // Cerramos la fila anterior y comenzamos una nueva } $output .= '
'; $output .= 'Imagen ' . ($index + 1) . ''; // Verificamos si hay un CTA y un enlace if (!empty($item['cta']) && !empty($item['link'])) { $output .= '' . esc_html($item['cta']) . ''; } $output .= '
'; } } else { $output .= '

No hay imágenes disponibles para mostrar.

'; } $output .= '
'; // Cerramos el div del grid return $output; } // Registramos el shortcode add_shortcode('grid_imagenes', 'generar_grid_imagenes'); // CSS BG function agregar_css_personalizado() { if (is_singular('events')) { // Cambia 'events' por el nombre de tu CPT $post_id = get_the_ID(); $css_value = get_post_meta($post_id, 'css', true); // Obtener el valor del metacampo 'css' // Verificar si el metacampo tiene contenido if (!empty($css_value)) { // Permitir solo CSS dentro de la etiqueta '; } } } add_action('wp_head', 'agregar_css_personalizado'); Sway Fest - Mítics
[grid_imagenes]

No hi ha dues nits iguals

Mítics Festival 2024
Aniversari La Ruta
Contacto Nadal 2024
Cap d’any 2024
9 Aniversari
Rockola Nadal 2024