Support

Account

Home Forums Front-end Issues the_field working only one time

Solving

the_field working only one time

  • Hello,
    I started using ACF recently and I have a probleme with using basic text and showing it with the_field option I can only show one text and the other are showing Empty if I check them I have 3 titles to show they work separatly but not all together

    I don’t know if it’s clear
    Thank you for reading my probleme 🙂

  • Going to need more information.

    Information about the fields: field type? Are they sub fields of any other type of field?

    The code you are using when to show the fields.

  • The other 3 are just duplicate from this one (picture)
    and I use this line to show it
    <?php the_field('categories_1');?>

  • There isn’t any reason, given the information you have provided, that one field would show and others would not.

  • When I tried get_field method it show the others empty but if I place them in first they show properly but only one by one so they all work correctly but I can only do it once

    I am struggling with that

    Thanks for your reply

  • Please provide code where you are trying to show all 3, the actual code that is not working.

  • <?php get_header(); ?>
        <main id="swup">
            <div class="container">
    			<img id="logo" src="<?php the_field('logo'); ?>" alt="Logo">
    		</div>
    		
    		<!-- Catégrories 1 -->
    		<div class="container categories-container">
    		    <div class="row">
    		        <div class="col-sm-6">
    		            <h1 class="landing-animation categorie-title">
                            <?php the_field('categories_1');?>
                        </h1>
    		        </div>
    		        <div class="col-sm-6">
    		          <?php
                        $args = array(
                            'post_type' => 'categories_1',
                            'posts_per_page' => 15 );
                            
                        $loop = new WP_Query( $args );
                        ?>
                        <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
                        <div class="col sub-categories-container">
                            <a class="title-url" href="<?php the_field('url')?>"><h1 class="landing-animation sub-categories-title"><?php the_field('title'); ?></h1></a>
                        </div>
                        <?php endwhile; ?>
    		        </div>
    		    </div>
    		</div>
    		
    		<!-- Catégories 2 -->
    		<div class="container categories-container">
    		    <div class="row">
    		        <div class="col-sm-6">
    		          <h1 class="landing-animation categorie-title">
                        <?php the_field('categories_2');?>
    		          </h1>
    		        </div>
    		        <div class="col-sm-6">
    		          <?php
                        $args = array(
                            'post_type' => 'categories_2',
                            'posts_per_page' => 15 );
                            
                        $loop = new WP_Query( $args );
                        ?>
                        <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
                        <div class="col sub-categories-container">
                            <a class="title-url" href="<?php the_field('url')?>"><h1 class="landing-animation sub-categories-title"><?php the_field('title'); ?></h1></a>
                        </div>
                        <?php endwhile; ?>
    		        </div>
    		    </div>
            </div>
            
            <!-- Catégories 3 -->
    		<div class="container categories-container">
    		    <div class="row">
    		        <div class="col-sm-6">
    		          <h1 class="landing-animation categorie-title">
    		              <?php the_field('categories_3')?>
    		          </h1>
    		        </div>
    		        <div class="col-sm-6">
    		          <?php
                        $args = array(
                            'post_type' => 'categories_3',
                            'posts_per_page' => 15 );
                            
                        $loop = new WP_Query( $args );
                        ?>
                        <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
                        <div class="col sub-categories-container">
                            <a class="title-url" href="<?php the_field('url')?>"><h1 class="landing-animation sub-categories-title"><?php the_field('title'); ?></h1></a>
                        </div>
                        <?php endwhile; ?>
    		        </div>
    		    </div>
            </div>
            
            <!-- Catégories 4 -->
    		<div class="container categories-container">
    		    <div class="row">
    		        <div class="col-sm-6">
    		          <h1 class="landing-animation categorie-title">
    		              <?php the_field('categories_4')?>
    		          </h1>
    		        </div>
    		        <div class="col-sm-6">
    		          <?php
                        $args = array(
                            'post_type' => 'categories_4',
                            'posts_per_page' => 20 );
                            
                        $loop = new WP_Query( $args );
                        ?>
                        <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
                        <div class="col sub-categories-container">
                            <a class="title-url" href="<?php the_field('url')?>"><h1 class="landing-animation sub-categories-title"><?php the_field('title'); ?></h1></a>
                        </div>
                        <?php endwhile; ?>
    		        </div>
    		    </div>
            </div>
        <?php get_footer(); ?>
       </main>
       <div class="transition-swipe overlay"></div>
        </body>
    </html>
  • What template file is this code from? What does the template display?

  • This template display the landing page

  • I do not see a main WP loop for the current post “The Loop” https://developer.wordpress.org/themes/basics/the-loop/

    You are doing sub queries based on these fields, what type of fields are they?

    On top of this I do not understand what the queries are doing or why they are being done.

    Additionally, you do not have any calls to setup_postdata() or wp_reset_postdata() so your sub queries are interfering with the main WP query and this would explain why you’re not getting values when you think you should be.

    When exactly are you trying to use these fields for and what is this template file trying to accomplish?

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

The topic ‘the_field working only one time’ is closed to new replies.