Forums

Advanced MySQL: 1 query to get latest X posts of each specific category (1 post)

  1. Lasha
    Member
    Posted 8 months ago #

    WordPress & MySQL Gurus: I'm looking to write a SINGLE custom SQL query to retrieve the latest 7 posts from each of my 6 specific categories of a custom post type.

    I know how to query custom post types and taxonomies, but my SQL knowledge is limited. I don't know how to get WordPress to give me 7 latest posts from each of the 6 categories. Doesn't really matter what order it's returned, as long as the content is there.

    Example: If I have categories 1, 2, 3, 4, 5, 6, I would like to retrieve the 7 latest posts from each of those categories. Specifically, the query should pull the 7 latest posts for category 1, 7 latest posts for category 2, and so forth, all with a single query.

    I don't want to have 6 separate WP_Query instances as it's not efficient.

    Anyone care to lend a helping hand? :)

Reply

You must log in to post.

About this Topic