How to sort my display results by more than one item?

Hi there, I have a loop which I want to sort by more than 1 item:

  • I have a custom taxonomy ‘label’ which is assigned to the post,page and event post types
  • I have a term ‘home-page-hero’ which is assigned to the label taxonomy
  • I have a term ‘pin’ which is assigned to the label taxonomy
  • In my loop I am displaying the most recently published 10 posts which have the ‘home-page-hero’ term assigned to the label taxonomy
  • but I also want the ability to ‘pin’ a post if it is older than the most recent 10

So I guess I am saying I want to display a maximum of 10 posts, with any posts that have BOTH the ‘pin’ term AND the ‘home-page-hero’ term assigned first (sorted by publish date DESC), then whatever is remaining out of the 10, to display any posts which have ‘home-page-hero’ assigned to them, and are not included already (sorted by publish date DESC).

Does this make sense? Is this possible? If so please could someone guide me with the syntax?

Thank you so much in advance,

Keith

Hi Keith, sorry for the long wait!

This is going to be a bit complex, and you probably won’t be able to make this happen with core Loop parameters in one loop. Saving the query will avoid making multiple database trips. Here’s how I’d go about it:

<Set query="homepage-posts" type="post" post_type="post" taxonomy="label" terms="home-page-hero" orderby="date" order="desc" />

  <Loop query="homepage-posts">
    <If check="{Loop type=taxonomy_term taxonomy=label post=current}{Field name /},{/Loop}" includes value="pin">
      ... pinned posts here ...
    </If>
  </Loop>
  <Loop query="homepage-posts">
    <If check="{Loop type=taxonomy_term taxonomy=label post=current}{Field name /},{/Loop}" not_includes value="pin">
      ... non-pinned posts here ...
    </If>
  </Loop>

Let me know if you have any questions!