WordPress meta_query不起作用

时间:2017-04-27 03:23:53

标签: wordpress

我在WordPress中使用meta_query时遇到问题。 iv尝试的meta_key为wpcargo_status,值为Delivered。问题是它仍然处于其他状态。这就是iv尝试过的......

$wpc_report_args = array(
    'post_type'         => 'shipment',
    'post_status'       => 'publish',
    'posts_per_page'    => -1,
    'meta_query'        => array(
        array( 
            'key'           => 'status',
            'value'         => 'Delivered',
            'type'          => 'CHAR',
            'compare'       => '=', 
        )
    ),      
);

$the_query = new WP_Query( $wpc_report_args );
// The Loop
    if ( $the_query->have_posts() ) :
    while ( $the_query->have_posts() ) : $the_query->the_post();
        echo get_the_ID().'<br />';
        echo get_post_meta(get_the_ID(), 'shipper_name', true).'<br />';
        echo get_post_meta(get_the_ID(), 'status', true).'<br />';
    endwhile;
    endif;
    // Reset Post Data
    wp_reset_postdata();

On my database

Output of my query

你知道我的代码有什么问题吗?

更新

我已经尝试了这个并且它正在运行,但我需要多个meta_query

'meta_key' => 'status',
'meta_value' => 'Delivered', 
'meta_compare' => '=',

3 个答案:

答案 0 :(得分:1)

我看到WP_Query没有错误。您的查询可能存在冲突,或者存在重叠的问题。

  1. 停用其他插件
  2. 主题冲突
  3. 检查parse_query - 此挂钩将在WP_Query之后执行。

答案 1 :(得分:1)

试试这个

 Mat frame;
Mat prevFrame;

while (capture.isOpened()) {
    capture.read(frame);
    vector<Rect> cars; // center of rectangles where each rectangle contains the detected object
    vector<Rect> prevCars; // to store previous tracked rectangles

    // Detects objects of different sizes in the input image. The detected objects are returned as a list of rectangles.
    car_cascade.detectMultiScale(frame, cars, 1.1, 2);

    if(!prevFrame.empty()) {
        car_cascade.detectMultiScale(prevFrame, prevCars, 1.1, 2);
    } else {
        cout << "EMPTY" << endl; // for testing
    }

    cout << "current : " << cars.size() << endl; // print out number of cars
    cout << "previous: " << prevCars.size() << endl; // print out number of cars


    // more code goes here which I haven't written here

    frame.copyTo(prevFrame); // set previous frame to current frame
    imshow("Video", frame);

    char key = waitKey(33);
    if (key == 'q')
    {
        break;
    }
}

类型 - 默认值为“CHAR”

答案 2 :(得分:0)

$wpc_report_args = array(
    'post_type'         => 'shipment',
    'post_status'       => 'publish',
    'posts_per_page'    => -1,
    'meta_query'        => array(
        array( 
            'key'           => 'wpcargo_status',
            'value'         => 'Delivered',
            'type'          => 'CHAR',
            'compare'       => '=', 
        )
    ),      
);

$the_query = new WP_Query( $wpc_report_args );
// The Loop
    if ( $the_query->have_posts() ) :
    while ( $the_query->have_posts() ) : $the_query->the_post();
        echo get_the_ID().'<br />';
        echo get_post_meta(get_the_ID(), 'shipper_name', true).'<br />';
        echo get_post_meta(get_the_ID(), 'status', true).'<br />';
    endwhile;
    endif;
    // Reset Post Data
    wp_reset_postdata();