Ok so I have this code to Query posts from a certain ID:


     $valid_post_types = array ('agencies','pro-awards-winners','marcawards','topshops');

    $args = array(
       'post_type' => $valid_post_types,
       'post_status' => 'publish',
       'pagename' => 210639,
       'posts_per_page' => -1       

  $query = new WP_Query( $args );
  // The Query
  query_posts( $args );

  //The Loop
  while ( have_posts() ) : the_post();
 echo '
 echo '</li>';

// Reset Query

The posts aren't displaying of course...Is there something I'm doing wrong?

  • There are a number of errors there and it would be very helpful to know exactly what you want to achieve in order to help you. If you are trying to get a single post by ID for example, then the pagename parameter and the array of post types are irrelevant. Aug 8, 2016 at 21:39
  • Isn't this your question from wordpress.stackexchange.com/questions/233942/… ? Aug 8, 2016 at 21:41
  • Hi I'm looking to get a page ID that displays those post types on it's page
    – MikeL5799
    Aug 8, 2016 at 21:41
  • Yeah I'm trying to do it a different way this time
    – MikeL5799
    Aug 8, 2016 at 21:43
  • well if you already know the pagename why would you need the ID?
    – bynicolas
    Aug 8, 2016 at 23:10

2 Answers 2


$args = array(
    'post_type' => 'post',  //Specifying the type of posts
    'cat'=> 1,    //Selecting post category by ID to show
    'posts_per_page' => 4,  //No. of posts to show      
    'paged' => $paged       //For pagination
//You dont need to use query_posts( $args ); since you are using wp_query
$query = new WP_Query( $args ); 

Use while loop like this

while ( $query->have_posts() ) : $query->the_post();   

Instead of this

while ( have_posts() ) : the_post();    

In case if you don't know where to find post ID, Read this article to know about post ID

  • Thanks, buit I'm trying to query the posts on a specific page and not by category ID
    – MikeL5799
    Aug 9, 2016 at 14:07
  • I am little confused about your question, If you can elaborate a little more that what exactly you want to achieve then I might help you.
    – Rishabh
    Aug 11, 2016 at 4:15

I solved the problem by posting adding this: $list_args2 = array( "post_type" => "any", "post__in" => get_post_meta( 210639, 'storylist', true), "orderby" => "post__in", 'post_status' => 'publish' );

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.