如何在wordpress中修改wp_query

How to modify wp_query in wordpress

我正在使用 wordpress,我想在 wp_query 中传递一个参数名称“post_title”,这样我就可以更改查询并获得正确的数据,但是我的查询没有更改(没有像我预期的那样显示),我尝试使用以下代码

$args = array(
    'post_type' => 'user',
    'posts_per_page' => -1,
     'post_title' => $_GET['post_title'],
    'post_status' => [ 'publish']
);
$query = new WP_Query($args);

当我打印我的 $query->request 时,我得到以下查询

[request] = "SELECT   MZAGsQVeposts.* FROM MZAGsQVeposts  WHERE 1=1  AND MZAGsQVeposts.post_type = 'user' AND ((MZAGsQVeposts.post_status = 'publish')) ORDER BY MZAGsQVeposts.post_date DESC";

但预期的查询是

"SELECT   MZAGsQVeposts.* FROM MZAGsQVeposts  WHERE 1=1  AND MZAGsQVeposts.post_type = 'user' AND ((MZAGsQVeposts.post_status = 'publish')) AND MZAGsQVeposts.post_title='Lisa I' ORDER BY MZAGsQVeposts.post_date DESC";

我哪里错了?提前致谢。

遗憾的是,您无法在 wp_query 中按标题查询 post,这不是公认的参数。 (参见 WP_Query for more info) however you can use get_page_by_title 并以这种方式传递标题,它将 return 具有该标题的 post object。