0

Haven’t slept in about 30 hours now, can someone please help as the below code doesn’t work, it just displays all posts etc :|

<?php $args = array
  (
        'page' => array(139, 54)
  );

  $loopy = new WP_Query($args);
  while ($loopy->have_posts()) : $loopy->the_post(); ?>
        <div class="item"><?php the_title(); 
              echo '<br ?>';

        echo '</div>';      
  endwhile; 

?>

0

2 Answers 2

3

page is not an accepted parameter for WP_query , you can use page_id but that doesn't accept an array , only one specific ID, so just use post__in like this:

<?php $args = array(
        'post__in' => array(139, 54)
  );

  $loopy = new WP_Query($args);
  while ($loopy->have_posts()) : $loopy->the_post(); ?>
        <div class="item"><?php the_title(); 
              echo '<br ?>';

        echo '</div>';      
  endwhile; 

you can read more about the accepted parameters of wp_query at the codex

2
  • Thanks, doesn't seem to work though and the page ids are there
    – Keith
    Commented Mar 16, 2011 at 0:30
  • or post_type => "any" if you are not expecting pages only
    – Bainternet
    Commented Mar 16, 2011 at 0:43
0

Found the answer.

I have to tell wordpress I want posts in conjunction with Bainternet's code:

'post_type' => 'page',
1
  • Where to put ''post_type' => 'page'.... Please provide me the full code for this problem.
    – AKB
    Commented Jul 8, 2021 at 7:28

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.