Support

Account

Home Forums General Issues Can not get repeater row/data on search page (search.php)

Solving

Can not get repeater row/data on search page (search.php)

  • Hello all,
    Hope you all are having a good day. I am facing an unusual issue while trying to get repeater data from posts on search page. Simple text fields are showing data fine, but when trying to get data from repeater rows I get nothing. I am pasting the complete code from the search file here. As you will notice I have tried all possible ways but noting works. line number 94: the_field(‘alternate_title’, $post->ID); this works but repeater entries are not showing.

    Thanks in advance.

    <?php
    /**
     * The template for displaying search results pages
     *
     * @link https://developer.wordpress.org/themes/basics/template-hierarchy/#search-result
     *
     * @package H2
     */
    
    get_header();
    ?>
    <?php 
    $rows = get_field('activities');
    var_dump('<hr><pre>', $rows);
    if($rows)
    {
        echo '<ul>';
    
        foreach($rows as $row)
        {
            echo '<li>sub_field_1 = ' . $row['title'] . ', etc</li>';
        }
    
        echo '</ul>';
    }
     ?>
    <ul>
    <?php foreach (get_field('activities', 60) as $row) :?>
        <li><?php print $row['title'] ?></li>                  
    <?php endforeach; ?>
    </ul>
    <?php
    
    global $query_string;
    //var_dump('<pre>', $_GET["s"]);
    //var_dump('<pre>', wp_parse_str( $query_string, $search_query ));
    // args
    
    // $search_query = array(
    //     'post_type' => 'math',
    //     'meta_query' => array(
    //         array(
    //             'key' => 'activities_$_title',
    //             'value' => $_GET["s"],
    //             'compare' => '='
    //         )
    //     )
    // );
    wp_parse_str( $query_string, $search_query );
    
    $search = new WP_Query( $search_query ); 
    //var_dump('<pre>', $search); ?>
    
    <style type="text/css">
        i {font-size: 12px;}
    </style>
    	<main class="site-main math-base">
            <div class="container">
                <div class="row">
                    <div class="left-col xo-col">
                        <?php //get_template_part( 'template-parts/sidebar', 'left' ); ?>
                        <div class="math-nav-div">
                            <?php h2_menu('footer-one', 'nav-menu') ?>
                                
                            <form action="<?php echo home_url( '/' ) ?>" method="get" role="search">
                                <div class="input-with-btn">
                                    <label class="work-around" for="search6">Search the Math</label>
                                    <input type="search" id="search6" class="form-control" name="s" placeholder="Type Here" value="<?php the_search_query(); ?>">
                                    <input type="hidden" name="post_type" value="math">
                                    <button class="btn" type="submit"><span class="fa fa-search"></span><span class="work-around">Search here</span></button>
                                </div> 
                            </form>
                                
                        </div>
                    </div>
                    <div class="col-80 xo-col">
    
                            <header class="page-header">
                                <h1 class="page-title">
                                    <?php
                                    /* translators: %s: search query. */
                                    printf( esc_html__( 'Search Results for: %s', 'h2' ), '<span>' . get_search_query() . '</span>' );
                                    ?>
                                </h1>
                            </header><!-- .page-header -->
                            <?php if( $search->have_posts() ): 
                                while ( $search->have_posts() ) : $search->the_post();
                                    if(get_post_type()=='math'):
                                        the_title();
                                        echo "<i>after title</i><hr>";
                                        echo $post->ID;
                                        echo "<i>after id</i><hr>";
                                        the_field('alternate_title', $post->ID);
                                        echo "<i>after alternate_title</i><hr>";
                                        the_field('subdomains', $post->ID);
                                        
                                        echo get_post_type(); ?>
    
                                        <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    
                                            <?php if( have_rows('activities', $post->ID) ): ?>
                                                <?php echo $count = 0; ?>
                                                
                                                <?php while( have_rows('activities', $post->ID) ): the_row();
                                                    // vars
                                                    $title = get_sub_field('title');
                                                    $primary_content_standards = get_sub_field('primary_content_standards');
                                                    $primary_math_practices = get_sub_field('primary_math_practices');
                                                    $description = get_sub_field('description'); ?>
    
                                                    <div class="search-result-wrap">
                                                        <h2><?php echo $title; ?></h2>
                                                        <?php echo $description; ?>
    
                                                        <h3>Primary Content Standards Addressed by Resource: <small><?php echo $primary_content_standards; ?></small></h3>
                                                        <h3>Primary Math Practices Addressed by Resource: <small><?php echo $primary_math_practices; ?></small></h3>
                                                    </div>
                                                <?php endwhile; ?>
                                                
                                            <?php endif; ?>
                                        </article><!-- #post-<?php the_ID(); ?> -->
                                        
                                    <?php endif;
                                endwhile;
                               
                            endif; ?>
    
                    </div>
                </div>
            </div>
        </main>
    <?php
    get_footer();
    
  • The code at the top of the page after get_header() is not in “The Loop”. ACF cannot get the values of the fields because it does not know what post to get them from.

  • @hube2 Sir thats understood, but i am trying everything, right next to that code you can see i am providing a hardcode id, I am also doing the same thing in wp loop in the middle of the code, nothing seems to work.

  • I don’t see anything wrong with the loop on the repeater, given what I assume to be the case, that the repeater is a top level field on the post.
    are the fields in this section

    
                                        echo "<i>after title</i><hr>";
                                        echo $post->ID;
                                        echo "<i>after id</i><hr>";
                                        the_field('alternate_title', $post->ID);
                                        echo "<i>after alternate_title</i><hr>";
                                        the_field('subdomains', $post->ID);
    

    what happens if you add this to that section

    
    echo '<pre>'; print_r(get_field('activities'); echo '</pre>';
    
  •  <?php if( have_rows('activities', $post->ID) ): ?>
                                                <?php echo $count = 0; ?>
                                                
                                                <?php while( have_rows('activities', $post->ID) ): the_row();
                                                    // vars
                                                    $title = get_sub_field('title');
                                                    $primary_content_standards = get_sub_field('primary_content_standards');
                                                    $primary_math_practices = get_sub_field('primary_math_practices');
                                                    $description = get_sub_field('description'); ?>
    
                                                    <div class="search-result-wrap">
                                                        <h2><?php echo $title; ?></h2>
                                                        <?php echo $description; ?>
    
                                                        <h3>Primary Content Standards Addressed by Resource: <small><?php echo $primary_content_standards; ?></small></h3>
                                                        <h3>Primary Math Practices Addressed by Resource: <small><?php echo $primary_math_practices; ?></small></h3>
                                                    </div>
                                                <?php endwhile; ?>
                                                
                                            <?php endif; ?>

    That the code that is suppose to show me my data from acf repeater on this post. And yes my repeater is first level of its group on the posts

  • btw print_r returns nothing.

  • Got an interesting change now,
    Print_r is now returning number of acf rows in each post.

  • I can only guess that there is something interfering with ACF’s queries to get the values. I would try deactivating all other plugins and if that does not work to see what results I get using one of the basic 20XX themes to try an narrow down where to look deeper.

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

You must be logged in to reply to this topic.