Support

Account

Home Forums General Issues WP_Query Results Issue

Solved

WP_Query Results Issue

  • Hi

    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 (2) when I assign
    $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
    ACF Version: 5.9.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

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.