admin管理员组文章数量:1327969
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.
本文标签: phpUse WPQuery to match to specific repeater row in post
版权声明:本文标题:php - Use WPQuery to match to specific repeater row in post 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742174147a2427263.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论