Posts Tagged ‘code’

Query WordPress posts excluding a category

I just spent a while trying to figure this one out so I figured I’d post my code for my solution. The problem was trying to loop through and show my most recent articles excluding the asides in my individual pages’ sidebar. I played with get_posts() and kept failing. I did it with the help of one of The Loop examples on the WordPress forums.

This code loops through the most recent 10 posts excluding my asides category and does a simple output for the sidebar.


have_posts()) : $my_query->the_post();
?>
    

  • %s1 / %s2