How do i show the latest post from a child category?

I have the category Photos, but I want to only show the latest post from the Child category "Paparazzi"

what do i add to the code below to do this

query_posts('category_name=photos&showposts=1'); while(have_posts()) : the_post(); 

1 Answer 1


Just change your query to search for the category you want.

$qry = new WP_Query('category_name=paparazzi&showposts=1');
while($qry->have_posts()) : $qry->the_post(); 

That should most likely be all you need to do.

And please don't use query_posts. It alters the main query and can break things.

  • That didn't work, because paprazzi is a child category
    – Mihad Aiko
    Commented Apr 8, 2013 at 21:51
  • That doesn't matter. The query doesn't care about the parent/child status, and I have tested that. You do need to use the slug and not the name though.
    – s_ha_dum
    Commented Apr 8, 2013 at 22:06

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.