Edit: I will try to explain in detail my problem. I am working on a portfolio site. There are a few custom post types: Projects, Publications, Exhibitions, Lectures, and Slides. The home page consists of the following sections:
- slider with Slides
- portfolio consisting of:
- selected (marked by Client) Projects, Publications, Exhibitions, and Lectures
- and remaining Projects, Publications, Exhibitions, and Lectures
- awards section
Now, I have a problem with the portfolio section. It is to be paged in order to use Infinite Scroll by Desandro - the next posts are loaded after clicking the "Load more" button. The first 10 posts are these marked 'selected' (1st custom field) by the Client in a particular order determined by the 2nd custom field (from 1 to 10). The remaining posts are to be ordered by date descending.
I used wp_query to query custom posts and meta_query to get these 'selected' posts on top and sort them ascending. I tried to sort the remaining posts by date but I'm stuck.
Take a look at my wp_query args:
'post_type' => array( 'projekty', 'publikacje', 'wystawy', 'wyklady' ), 'post_status' => array( 'publish' ), 'meta_query' => array( 'relation' => 'OR', 'home_rest' => array( 'key' => 'sticky_home', 'compare' => 'NOT EXISTS' ), 'home_sticky' => array( 'key' => 'sticky_home', 'compare' => 'EXISTS' ), 'orderby' => array( 'home_rest' => 'DESC', 'home_sticky' => 'ASC', ), 'posts_per_page' => 10, 'paged' => get_query_var('paged'),
So I achieved the first goal (you can see red blocks representing 'selected' posts here: http://redesigned.pl/_sts/bxbstudio/strona-glowna-infinitemasonry/.
I thought I would be able to do this multiple
orderby sorting. Firstly, sort by
sticky_home field (true/false field) to get selected posts on top; Secondly, sort them ascending by
sticky_home_order field; Thirdly, sort posts with
false descending by date published. Do you think it is possible to get all of that in one query? or perhaps there is another way to achieve that?
I'll appreciate any help.
Edit: I am no experienced PHP programmer. Having read through various content on stack exchange, I think that perhaps using
usort could be the way. together with
get_posts? but on the other hand, pagination will brake..
sticky_homeas a taxonomy term, and have 2 terms
not_sticky_home, then this would see a major speed boost and be able to handle more visitors at the same time. Also, your use of
pagedimplies that this isn't a second query on the page, but a replacement query. Is there a reason you didn't use
sticky_homeas a taxonomy term? for each custom post that is queried?