0

I work on the WordPress project I created testimonials in a special file called testimonials.php and I called the file on the page about us by get_template_part and it works fine but when I called (testimonials.php) to the home page not show all values.

Use the Advanced Custom Fields plugin

<!-- Start Section Testimonials -->
<section class="testimonials section-padding">
<div class="carousel-right col-lg-7 col-md-7 col-sm-7 col-xs-12">
    <div class="owl-carousel">
        <?php $testimonials = array ('post_type' => 'Testimonials' , 'order' => 'ASC');
            $query = new wp_query($testimonials);
                if ($query->have_posts()) {
                while ($query->have_posts()){
                    $query->the_post(); ?>
                        <!-- Start Item 1 -->
                        <div class="testimonials-item">
                            <!-- Testimonials Text -->
                            <div class="testimonials-text-item">
                                <?php the_content(); ?>
                            </div>
                            <!-- Testimonials Title -->
                            <div class="testimonials-title clearfix">
                                <!-- Title Img -->
                                <div class="title-img">
                                    <img src="<?php the_field('image'); ?>" alt="testimonials">
                                </div>
                                <!-- Title Text -->
                                <div class="title-text">
                                    <h3><?php the_title(); ?></h3>
                                    <p><?php the_field('small_title'); ?></p>
                                </div>
                            </div>
                        </div>
                        <!-- End Item 1 -->
                    <?php }} ?>
    </div>
</div>
<?php wp_reset_postdata(); ?>
<!-- Start Title -->
<?php $testimonials = get_field('testimonials'); ?>
<div class="container">
    <div class="row">
        <div class="col-lg-4 col-md-5 col-md-5 col-sm-4 col-xs-12">
            <div class="testimonials-text clearfix">
                <div class="title">
                    <span><?php echo $testimonials['small_title']; ?></span>
                    <h2><?php echo $testimonials['main_title']; ?></h2>
                </div>
                <div class="text-p">
                <?php echo $testimonials['description']; ?>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- End Title -->
</section>

The part that does not appear from all values

<span> <? php echo $ testimonials ['small_title']; ?> </ span>
<h2> <? php echo $ testimonials ['main_title']; ?> </ h2>
<? php echo $ testimonials ['description']; ?>
  • Do they use group values ? – Gregory Jun 14 at 7:45
0

as you use multiple $testimonials i suppose those are group values.

then you need to use get_sub_field() in place of get_field()

so it should look like

$term = get_queried_object();
$testimonials = get_sub_field('testimonials',$term);
echo $testimonials['small_title'];
echo $testimonials['main_title'];
echo $testimonials['description']; 

Please refer to ACF documentation when you use non classical fields. https://www.advancedcustomfields.com/resources/group/

  • Unfortunately, the values also did not show – Yasir Kareem Jun 15 at 22:01
  • i edited my answear with adding queried object. – Gregory Jun 17 at 8:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.