By default the output of a WordPress query is to show a specific number of or all posts that belong to all the categories (or custom taxonomies). What if you want to output say only a maximum of 3 portfolio CPT items from each portfolio_category?

For this one approach is to:

  • get all the terms of the taxonomy in question
  • loop through them and for each term, get the IDs of recent 3 items into an array
  • flatten the array
  • remove duplicates
  • run a WP_Query looping these IDs and output the items

Here's the PHP code:

This is a premium members-only content.

To view the rest of the content, please sign up for membership ($47/month or $399 one-time).

Already a member? Log in below or here.

Need help implementing a tutorial in your site or want to hire me for custom work?


Find the article helpful and wish to donate?



You need to be logged in to view and post comments.
Not a member yet? Join here.
linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram
%d bloggers like this: