So i have a repeater inside post-type 'properties' that stores Lot No and Auction Date for all the Auctions a property is in.
When going into an event page, say for 12th August it needs to list all of the properties in this auction in Lot No order.
When i use WP Query i'm doing it as so:
function my_posts_where( $where ) {
$where = str_replace("meta_key = 'auctions_$", "meta_key LIKE 'auctions_%", $where);
return $where;
}
add_filter('posts_where', 'my_posts_where');
$args = array (
'post_type'=>'properties',
'post_status'=>'publish',
'posts_per_page'=> 40,
'paged'=> $paged,
'suppress_filters' => false,
'meta_query' => array(
'proparray' => array(
'key' => 'auctions_$_auction_date',
'value' => $today2,
'compare' => 'LIKE',
),
'lot-nos' => array(
'key' => 'auctions_$_lot_no',
'type' => 'NUMERIC',
),
),
'orderby' => array(
// 'auction-dates' => 'ASC',
'lot-nos' => 'ASC',
),
);
$wpb_all_query = new WP_Query($args);
My problem is that it's picking up Lot Nos from other rows. So if a property has the following date:
Auction Date : 7th June 2020 Lot No: 2 Auction Date: 12th August 2020 Lot No: 14
It is picking up the auction date 12th August 2020, but ordering it as Lot No 2, NOT 14. I need it to match to the specific row of the date in question, then get the Lot No from that row. is this possible?
So i have a repeater inside post-type 'properties' that stores Lot No and Auction Date for all the Auctions a property is in.
When going into an event page, say for 12th August it needs to list all of the properties in this auction in Lot No order.
When i use WP Query i'm doing it as so:
function my_posts_where( $where ) {
$where = str_replace("meta_key = 'auctions_$", "meta_key LIKE 'auctions_%", $where);
return $where;
}
add_filter('posts_where', 'my_posts_where');
$args = array (
'post_type'=>'properties',
'post_status'=>'publish',
'posts_per_page'=> 40,
'paged'=> $paged,
'suppress_filters' => false,
'meta_query' => array(
'proparray' => array(
'key' => 'auctions_$_auction_date',
'value' => $today2,
'compare' => 'LIKE',
),
'lot-nos' => array(
'key' => 'auctions_$_lot_no',
'type' => 'NUMERIC',
),
),
'orderby' => array(
// 'auction-dates' => 'ASC',
'lot-nos' => 'ASC',
),
);
$wpb_all_query = new WP_Query($args);
My problem is that it's picking up Lot Nos from other rows. So if a property has the following date:
Auction Date : 7th June 2020 Lot No: 2 Auction Date: 12th August 2020 Lot No: 14
It is picking up the auction date 12th August 2020, but ordering it as Lot No 2, NOT 14. I need it to match to the specific row of the date in question, then get the Lot No from that row. is this possible?
Share Improve this question asked Aug 14, 2020 at 8:48 adamsuperadamsuper 11 Answer
Reset to default 0WP_Query will get posts, the whole post. If another repeater field instance has data for LotNos the sort parameter will not understand what you mean.
What I'd do is getting all posts just by the date. Than I'd make a loop and create an array of objects with the data you need from each post (title, LotNo, image, etc). Than I'd use php usort function to sort the posts by the LotNo.
Finally I'd do a foreach() with this sorted object to print the data.