Support

Account

Home Forums Add-ons Repeater Field Repeater w/ Query

Helping

Repeater w/ Query

  • Hi,

    Each of my posts are like “Asian animals”, “American animals”, “African animals”.
    I’m using a repeater as each row is a animal : A custom image, a custom taxonomies and a custom url.
    When visitors are looking for snakes, I would like to show post title, and the row corresponding according to the row’s taxonomie.

    Here is my code :

    function my_posts_where( $pagepdf ) {
    	
    	$pagepdf = str_replace("meta_key = 'pagesdupdf_$", "meta_key LIKE 'pagesdupdf_%", $pagepdf);
    
    	return $pagepdf;
    }
    
    add_filter('posts_where', 'my_posts_where');
    
    // args
    $args = array(
    	'numberposts'	=> -1,
        'category'      => 2,
        'post_type'     => 'post',
        'meta_query'    => array(
                        'key' => 'pagesdupdf_$_contenu_de_la_page',
                        'value' => '"' . get_search_query()  . '"',
        
        )
    	);
    
                    
    // query
    $the_query = new WP_Query( $args );
    
    ?>
                <?php if( $the_query->have_posts() ): ?>
                <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
    
                <?php 
                if( have_rows('pagesdupdf') ): ?>
    
                <ul>
                    <?php while( have_rows('pagedupdf') ): the_row(); 
    
    		// vars
    		$image = get_sub_field('image_de_la_page');
    		$content = get_sub_field_object('contenu_de_la_page');
    		$link = get_sub_field('url_de_la_page');
    
    		?>
    
                    <li>
    
                        <?php if( $link ): ?>
                        <a href="<?php echo $link; ?>">
                            <?php endif; ?>
    
                            <img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt'] ?>" />
    
                            <?php if( $link ): ?>
                        </a>
                        <?php endif; ?>
    
                        <?php echo $content; ?>
    
                    </li>
    
                    <?php endwhile; ?>
    
                </ul>
    
                <?php endif;?>
                <?php endwhile; ?>
                <?php endif; ?>
    

    This won’t show anything, I tried to change de meta value with no results.
    I guess my $args isn’t set correctly but I really can’t find the way to get it.

    Thanks !

  • I’d correct some mistake.

    Here is the new code :

    function my_posts_where( $pagepdf ) {
    	
    	$pagepdf = str_replace("meta_key = 'pagesdupdf_$", "meta_key LIKE 'pagesdupdf_%", $pagepdf);
    
    	return $pagepdf;
    }
    
    add_filter('posts_where', 'my_posts_where');
    
    // args
    $args = array(
    	'numberposts'	=> -1,
        'category'      => 2,
        'post_type'     => 'post',
       // 'meta_query'    => array(
         //               'key' => 'pagesdupdf_$_contenu_de_la_page',
                    //'value' => '"' . get_search_query()  . '"',
                      //  'compare' =>'EXISTS')
    	);
    
    // query
    $the_query = new WP_Query( $args );
    
    ?>
                <?php if( $the_query->have_posts() ): ?>
                <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
    
                <?php 
                if( have_rows('pagesdupdf') ): ?>
    
                <ul>
                    <?php while( have_rows('pagesdupdf') ): the_row(); 
                    
                    $motcherche = get_search_query();
                    $motsdepage = get_sub_field('contenu_de_la_page');
                    
                    foreach( $motdepage as $mot ):
                    
                    if ( $motcherche == $mot) :
                    
    		// vars
    		$image = get_sub_field('image_de_la_page');
    		$content = get_sub_field('contenu_de_la_page');
    		$link = get_sub_field('url_de_la_page');
    
    		?>
    
                    <li>
    
                        <?php if( $link ): ?>
                        <a href="<?php echo $link; ?>">
                            <?php endif; ?>
    
                            <img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt'] ?>" />
    
                            <?php if( $link ): ?>
                        </a>
                        <?php endif; ?>
    
                        <?php echo $content; ?>
    
                    </li>
    
                    <?php endif; endforeach; endwhile; ?>
    
                </ul>
    
                <?php endif;?>
                <li>
                    <a href="<?php the_permalink(); ?>">
                        <?php the_title(); ?>
                    </a>
                </li>
                <?php endwhile; ?>
    
                <?php endif; ?>
    
                <?php wp_reset_query();	 // Restore global post data stomped by the_post().?>
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.