最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

wp query - WP_Query Results Issue with ACF

programmeradmin1浏览0评论

I have the following query set up

$argsar = array (
'numberposts'   => 1,
'post_type' => 'auctionroom',
'meta_key'  => 'auctionroom_username',
'compare' => '=',
'value'   => $auctionroomname
);
$the_queryar = new WP_Query($argsar);
if ($the_queryar->have_posts()) {
$causercheck = $the_queryar->found_posts;
$the_queryar->the_post();
$auctionroom_id = get_the_ID();
}

It should only return 1 result but it is returning the total number of auctionroom posts when I get

$causercheck = $the_queryar->found_posts;

Having numberposts or not gives the same incorrect total

Thanks in anticipation for any clues

Running Wordpress Version: 5.5.1 with ACF Version: 5.9.1

I have the following query set up

$argsar = array (
'numberposts'   => 1,
'post_type' => 'auctionroom',
'meta_key'  => 'auctionroom_username',
'compare' => '=',
'value'   => $auctionroomname
);
$the_queryar = new WP_Query($argsar);
if ($the_queryar->have_posts()) {
$causercheck = $the_queryar->found_posts;
$the_queryar->the_post();
$auctionroom_id = get_the_ID();
}

It should only return 1 result but it is returning the total number of auctionroom posts when I get

$causercheck = $the_queryar->found_posts;

Having numberposts or not gives the same incorrect total

Thanks in anticipation for any clues

Running Wordpress Version: 5.5.1 with ACF Version: 5.9.1

Share Improve this question asked Oct 10, 2020 at 10:39 Encore ServicesEncore Services 111 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 1

It seems that the format I used for $argsar needs to be changed to

$argsar = array (
        'post_type' => 'auctionroom',
        'meta_query' => array(
                  array(
                        'key'     => 'auctionroom_username',
                        'compare' => '=',
                        'value'   => $auctionroomname
                    )
                )
        );

Hope it helps someone

发布评论

评论列表(0)

  1. 暂无评论