I'm making one page website and I added a custom field on "Page" post type that asks "Use this page as a section:" Yes or No(with dropdown). I called all pages on template-onepage.php(custom template) using wp query

<?php $args = array(
  'post_type' => 'pages',
  'order' => 'ASC',
  'posts_per_page' => 50,
  'meta_query' => array(
        'key'     => 'field_5505a81b83234', // field key generated from acf plugin
        'value'   => 'Yes'
 $onepage = new WP_Query($args);

        <?php if ( $onepage->have_posts() ) : while ( $onepage->have_posts() ) : $onepage->the_post(); ?>

            <div class="section">

                <?php get_template_part( 'content', 'page' ); ?>


        <?php endwhile; endif; // end of the loop. ?>

Above I tried to get only those pages that set to Yes from custom field but it showing all pages. I want only those that set to "Yes" through custom field I asked the question about it so this is part II. Please help. Thanks.

Note: I used Advanced Custom Field for creating the field and the field type is "Select" with two option Yes and No.. Thanks Again..

1 Answer 1


Two issues here

  • The default page post type is page, not pages

  • Your meta_query is wrong, it should be an array of an array, not just an array

Your arguments should be

$args = array(
    'post_type'      => 'page',
    'order'          => 'ASC',
    'posts_per_page' => 50,
    'meta_query'     => array(
            'key'     => 'field_5505a81b83234', // field key generated from acf plugin
            'value'   => 'Yes'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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