Support

Account

Home Forums Add-ons Repeater Field repetear filter by sub_fields

Helping

repetear filter by sub_fields

  • Hi, i’m trying to filter a loop by two sub_fields. Apparently my code is right, but i cannot get the sub_fields to show. I will place to examples code:
    As you will see in the <li> i have to print the sub_fields: comienzo (is a picker time) and finalizacion (is a picker time) but with the first code i cannot print them. In the second code, i can print them but the arrays from args does not filter the posts.
    Hope you can help me and thanks.

    In the functions.php:

    //filter
    function my_posts_where( $where ) {
        
        $where = str_replace("meta_key = 'dia_y_horario_%", "meta_key LIKE 'dia_y_horario%", $where);
    
        return $where;
    }
    add_filter('posts_where', 'my_posts_where');

    In the template:

    1- it filters but i can’t get the value form the other sub_fiels:

    <?php
    																							$args = array(
    'posts_per_page'	=> -1,													'post_type'		=> 'any',									'meta_query'	=> array(										'relation'		=> 'AND',											array(											'key'		=> 'dia_y_horario_%_dia',														'compare'	=> 'LIKE',										'value'		=> 'lunes',											),											array(															'key'		=> 'dia_y_horario_%_lugar',														'compare'	=> 'LIKE',										'value'		=> 'Sala 1',											)										)												);												
    										$the_query = new WP_Query( $args );												?>
    <?php if( $the_query->have_posts() ): ?>													<ul>
    	<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
    		<li class="single-event" data-start="<?php echo the_sub_field('comienzo'); ?>" data-end="<?php echo the_sub_field('finalizacion'); ?>" data-event=<?php $postType = get_post_type_object(get_post_type()); 															if ($postType) {								    echo esc_html($postType->labels->name);													}  ?>>										<a href="<?php the_permalink(); ?>">													<em><?php the_title(); ?></em>												<small><?php echo the_sub_field('lugar'); ?> | 											<?php get_sub_field('dia');?></small>									</a>
    </li>
    													<?php endwhile; ?>													</ul>
    <?php endif; ?>
    												<?php wp_reset_query();	 // Restore global post data stomped by the_post(). ?>

    2- It does not filter, but i can get the value form the other subfiels:

    <?php 
      $args = array(												 	'category_name' => 'lunes',										 	'post_type' => 'any',									 	'meta_query' => array(									 		'relation'	=> 'AND',									 		array(									 			'key' => 'dia_y_horario_%_dia',									 			'value' => 'lunes',								 			'compare' => 'LIKE'										 			),												 		array(												 			'key' => 'dia_y_horario_%_lugar',											 			'value' => 'Sala 2',								 			'compare' => 'LIKE'										 			)											 		)												 	);												 $sala2 = new WP_Query($args);												 while($sala2->have_posts() ): $sala2->the_post();								 ?>												<?php if ( have_rows('dia_y_horario') ) : while ( have_rows('dia_y_horario') ) : the_row(); ?>														<li class="single-event" data-start="<?php the_sub_field('comienzo') ?>" data-end="<?php the_sub_field('finalizacion') ?>" data-event="<?php 												$postType = get_post_type_object(get_post_type());				if ($postType) {										    echo esc_html($postType->labels->name);														} ?>">										<a href="<?php the_permalink(); ?>">															<em class="event-name"><?php the_title(); ?></em>												<small><?php the_sub_field('lugar'); ?> <br> 										<?php the_sub_field('dia');?></small>									</a>			
    </li>
    <?php endwhile; ?>													<?php endif; ?>										<?php endwhile;										wp_reset_postdata(); ?>
  • the_sub_field() will not do anything unless it is in a have_rows() loop https://www.advancedcustomfields.com/resources/have_rows/

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘repetear filter by sub_fields’ is closed to new replies.