Home Forums Add-ons Flexible Content Field Recent post thumbnail flexible row


Recent post thumbnail flexible row

  • I’m trying to create a ACF flexible content row to display the most recent post thumbnails for a given category. However it keeps throwing a critical error and I’m not sure why.

    $section_id = get_sub_field('section_id')
    $categories = get_sub_field('categories');
    $tags = get_sub_field('tags');
    $postnum = get_sub_field('number_of_posts');
    // make sure it is an array, if only one is
    // selected it may return a single value
    if (!is_array($categories)) {
      $categories = array($categories);
    $tags = get_field('my_tags_field');
    if (!is_array($tags)) {
      $tags = array($tags);
    $args = array(
      'post_type' => 'post',
        'numberposts' => $postnum,
      'posts_per_page' => -1,
      'tax_query' => array(
        'relation' => 'OR',
          'taxonomy' => 'category',
          'terms' => $categories
          'taxonomy' => 'post_tag',
          'terms' => $tags
    $query = new WP_Query($args);
    <section class="post_row_with_thumbnails" id="<?php echo $section_id; ?>">
        <div class="container-fluid">
            <div class="row">
                <?php if( $query->have_posts() ) : while( $query->have_posts() ) : $query->the_post(); ?>
                <div class="col">
                    <a href="<?php the_permalink(); ?>">
                        <img src="<?php echo wp_get_attachment_url( get_post_thumbnail_id( $post->ID ) ); ?>" class="project_pics">
                        <h5 class="posttitle"><?php the_title(); ?></h5>
                        <h6 class="postdate"><?php the_date(); ?></h6>
                <?php endwhile; endif; wp_reset_postdata(); ?>

    I have tried substituting WP_Query() with get_posts() but it gives me the same critical error.

  • Seems I found the issue shortly after posting this, go figure…
    I was just missing a semicolon at the end of

    $section_id = get_sub_field('section_id')

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

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.