Meta query with order by another custom field

Question

I query custom posts using wp_query’s meta_query.
What I try to achieve:

  1. firstly, to show posts with meta_key “sticky_home” ordered by another meta_key “sticky_home_order” value (from 1 to 10).
  2. secondly, to show remaining posts ordered by date (descending).
    I know it is simple in two queries, but I need it in one query in order to have pagination used by infinite scroll.

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 here: http://redesigned.pl/_sts/bxbstudio/strona-glowna-infinitemasonry/. And I’m stuck.
I’ll appreciate any help.

0
, , jakesh_of_redesigned 3 years 2020-03-30T08:50:51-05:00 0 Answers 115 views 0

Leave an answer

Browse
Browse