• A client asked me to create a business directory within their existing site. I set up a custom post type ‘directory_listing’ and a hierarchal custom taxonomy ‘directory_listing _sector’ for the business sector (e.g. accountants, plumbers etc.)

    My problem:

    In the taxonomy template (‘taxonomy-directory_listing_sector.php’), I need all listings that have a custom meta field ‘directory_listing_type’ set to ‘Featured’ to be output first (and sorted either by ASC or random – haven’t decided yet), followed by the rest of the listings (themselves sorted either by ASC or random – haven’t decided yet), with no duplicates, and for pagination to work as normal over the aggregate.

    So, if pagination count is 25, and there are 5 listings within a specific taxonomy that are also set to be featured, on that term’s archive page the 5 featured listings will be displayed in their sort order first, followed by the first 20 remaining (and sorted) listings with that term that aren’t featured, then on page 2 the next 25 and so on…

    Of course, I can simply make 2 queries, the first for the featured listings, the second for all listings minus the featured listings, and output them one after another, but it’s incorporating pagination that is stumping me. I imagine what’s needed is a way of combining the two queries into one loop output (with JOIN?) and possibly some math (not my strong point!)

    If WP custom post types supported could be ‘sticky’ this would surely be a one click affair. As it is, I’ve tried everything I can think of, and been all over google for a few days to no avail.

    If any WP genius can point me in the right direction, that’d be great.

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘How to query featured items first in custom post type custom taxonomy loop?’ is closed to new replies.