Advanced Custom Fields Plugin: how to use a checkbox to allow a post to show up in desired “zone”?

wordpress.stackexchange https://wordpress.stackexchange.com/questions/78011

  •  04-11-2019
  •  | 
  •  

Question

I am having issues getting the below code to work. I created an Advanced Custom Field (top_articles) with a checkbox containing three options: top_articles_left, top_middle, top_articles_right. I would it is so that when you are within a post you can check off that you want that post featured and it then shows up in the respective three zones I have designated. How could I accomplish this with ACF and have it fetch the correct post in WordPress?

    <section class="top-articles">
        <h2>Top Articles</h2>

        <?php $articles_query = new WP_Query('category_name=main&posts_per_page=1');
        while ($articles_query->have_posts()) : $articles_query->the_post(); ?>
        <?php if (get_field('top_articles') == 'top_articles_left'): ?>
        <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
            <a href="<?php the_permalink(); ?>">
                <?php the_post_thumbnail('large'); ?>
            </a>
        </article>
        <?php endif; endwhile; ?>

        <?php $articles_query = new WP_Query('category_name=main&posts_per_page=1');
        while ($articles_query->have_posts()) : $articles_query->the_post(); ?>
        <?php if (get_field('top_articles') == 'top_articles_middle'): ?>
        <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
            <a href="<?php the_permalink(); ?>">
                <?php the_post_thumbnail('large'); ?>
            </a>
        </article>
        <?php endif; endwhile; ?>

        <?php $articles_query = new WP_Query('category_name=main&posts_per_page=1');
        while ($articles_query->have_posts()) : $articles_query->the_post(); ?>
        <?php if (get_field('top_articles') == 'top_articles_right'): ?>
        <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
            <a href="<?php the_permalink(); ?>">
                <?php the_post_thumbnail('large'); ?>
            </a>
        </article>
        <?php endif; endwhile; ?>

    </section>

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top