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. Home page consists of 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 problem with the portfolio section. It is to be paged in order to use Infinite Scroll by Desandro - next posts are loaded after clicking "Load more" button. First 10 posts are these marked 'selected' (1st custom field) by the Client in 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 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..