Support

Account

Home Forums General Issues Querying Custom Post Type

Helping

Querying Custom Post Type

  • Here is some code I am using to attempt to query my custom post type called ‘Testimonials’.

    The query runs and pulls 3 items (which is correct) and as I loop over these items, I want to output the ACF fields that are associated with each testimonial – title, description and videourl.

    I know the 3 items are being pulled but the ACF fields aren’t being displayed.

    Can you assist?

    I know it has to be something basic that I’m missing.

    I should also add that this query is run on a custom home page template.

    The ACF fields I am attempting to display are Flex Fields.

    <?php
    $args = array(
    ‘post_type’ => ‘testimonials’,
    ‘orderby’ => ‘title’,
    ‘order’ => ‘ASC’,
    );
    $testimonials = new WP_Query($args);
    if($testimonials->have_posts()) : while($testimonials->have_posts()) : $testimonials->the_post();
    ?>

    <div class=”services__grid-individual__more-info”>
    <div class=”services__grid-individual__more-info–content”>
    <h4><?php the_field(‘title’);; ?></h4>
    <p><?php the_field(‘description’); ?></p>
    <p><?php the_field(‘videourl’); ?></p>

    </div>
    </div>

    <p class=”services__grid-individual–title”><?php the_title(); ?></p>
    <br><br>

    <?php endwhile; endif; wp_reset_postdata(); ?>

  • You say that these are “Flex Fields” but I don’t see any loop for a flexible content field in your code https://www.advancedcustomfields.com/resources/flexible-content/

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

The topic ‘Querying Custom Post Type’ is closed to new replies.