[英]How to modify wp_query in wordpress
i am working with wordpress,And i want to pass one parameter name "post_title" in wp_query,So i can change query and can get correct data,But my query is not changed(not displaying as i expected),I tried with following code我正在使用 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);
when i print my $query->request then i getting following query当我打印我的 $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";
But expected query is但预期的查询是
"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";
Where i am wrong?我哪里错了? Thanks in advance.
提前致谢。
Unfortunately you can't query posts by title in wp_query, it's not a recognised argument.不幸的是,您不能在 wp_query 中按标题查询帖子,这不是公认的论点。 (See WP_Query for more info) however you can use get_page_by_title and pass the title that way and it'll return the post object with that title.
(有关更多信息,请参阅WP_Query )但是您可以使用get_page_by_title并以这种方式传递标题,它将返回带有该标题的帖子 object。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.