I need to create some pages with a custom field called categoria-pagina so I can display a list of these pages and their excerpt on my theme's index.php. I have already tried the code bellow, but if I use the args it doesn't display anything.

        $args = array(
            'meta_key' => 'categoria-pagina',
            'meta_value' => 'programas'

        $pages = get_pages($args);

        foreach ($pages as $page) {
          echo "<p>$page->post_title</p>";


Page custom fields


I don't know how to do it with Pages, but with Posts or CPT I use the following list of of args :

 <?php $args = array( 
                  'post_type' => 'post', 
                  'post_status' => 'publish', 
                  'meta_key' => 'votes_count', 
                  'orderby' => 'meta_value_num'; 

 $wp_query = new WP_Query( $args );

What does a print_r($args) return for you ?

  • Also found out that you need to declare this in your args 'post_type' => 'page' – Simon Aug 27 '15 at 22:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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