我在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();
你知道我的代码有什么问题吗?
更新
我已经尝试了这个并且它正在运行,但我需要多个meta_query
'meta_key' => 'status',
'meta_value' => 'Delivered',
'meta_compare' => '=',
答案 0 :(得分:1)
我看到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();