LIKE查询没有按预期返回数据



我真的不知道是什么问题。我认为我的代码是好的,但输出是错误的。我对WordPress一窍不通,请帮帮我。

elseif ($_GET['search']) {
$args = array(
'post_type' => 'head_to_toe_videos',
'post_status' => 'publish',
'meta_query' => array(
array(
'key' => 'post_title',
'value' => $_GET['search'],
'compare' => 'LIKE',
)
),
'posts_per_page' => 12,
);
}

您的查询是正确的,但需要像这样执行您的查询:

$the_query = new WP_Query( $args );
$result = $the_query->get_results();
echo "<pre>"; print_r($result); exit;

试试下面的代码,你的问题就会解决了。

elseif ($_GET['search'] != '') {
$args = array(
'post_type' => 'head_to_toe_videos',
'post_status' => 'publish',
'meta_key'   => 'post_title',
'meta_query' => array(
array(
'key' => 'post_title',
'value' => $_GET['search'],
'compare' => 'LIKE',
)
),
'posts_per_page' => 12,
);

$result = new WP_Query( $args );
}

最新更新