D
D
Dennis2020-03-02 16:34:41
WordPress
Dennis, 2020-03-02 16:34:41

How to show posts by checkbox condition in wordpress?

Colleagues, good afternoon! The essence of the problem is displaying a preview of a certain post (marked with a checkbox in the admin panel) in a custom wordpress page template. The Advanced Custom Fields plugin was installed, a field of type true/false was created in the form of a checkbox "display on the main page". I post the following code

<?php $posts = get_posts ("category=27&orderby=date&numberposts=10"); ?>
            <?php if ($posts) : ?>
            <?php foreach ($posts as $post) : setup_postdata ($post); ?>
                <li class="inner-news__item">
                    <div class="inner-news__item-wrap">
                        <a href="<?php the_permalink() ?>" rel="bookmark"><span class="inner-news__item-title"><?php the_title(); ?></span></a>
                        <?php the_excerpt(); ?>
                    </div>
                    <div class="inner-news__item-img">
                        <?php the_post_thumbnail();?>
                    </div>
                </li>
            <?php endforeach; ?>
            <?php endif; ?>

How to add validation for checked field?
Earlier there was an attempt to create a metabox for selection, the field is displayed in the admin panel, but the output condition does not work. Thanks in advance to all who respond!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex, 2020-03-02
@dennis_d

https://wp-kama.ru/function/wp_query#meta_query

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question