I have a custom post type ‘specials’ that has 2 meta fields ‘expiration_date’ and ‘featured’
Featured is just 1 or 0 and expiration date is a date picker field from ACF
I need to write a WP_Query that combines these two so that I can loop with pagination.
It should return all specials with a future date and then sort the ones where ‘featured’ = 1 above the rest.
Here is my code that doesn’t work. I had originally wrote it as 2 loops and merged but couldn’t get the posts per page to work right.
Thanks for reading!
$paged = ( get_query_var( 'page' ) ) ? absint( get_query_var( 'page' ) ) : 1; $args = [ 'post_type' => 'specials', 'posts_per_page' => -1, 'paged' => $paged, 'meta_query' => [ 'relation' => 'AND', 'expiration_date' => [ 'key' => 'expiration_date', 'value' => date('Ymd'), 'type' => 'DATE', 'compare' => '>=', ], 'featured' => [ 'key' =>'featured', ], ], 'order_by' => [ 'featured' => 'DESC', 'expiration_date' => 'DESC', ], ]; $loop = new WP_Query($args);
- FCC fines AT&T $100 million for misleading customers about throttled unlimited data plans
- Diary of an online dating scam: Man seduced by 'Aleksandra' goes public to warn others
- Delilah Hamlin stuns in custom made designer jeans as she enjoys a girls' dinner date at Craig's
- The best dating sites for 2019
- Why did Jack Fincham and Dani Dyer break up, does the Celebs Go Dating star have a new girlfriend and when was his cocaine scandal?
- Kate Iselin writes: Why I won’t ‘Ask for Angela’ on my next bad date
- Where are the Celebs Go Dating restaurants and bars and are they real?
- The growth of online dating
- 'Clash of Clans' TH13 Revealed for December With New Hero, No Release Date
- Chris Brown yard sale customer found 'weed in hoodie pocket' after buying clothing item from the rapper