wordpress 带有“post_title LIKE 'something%'”和类别的 WP_Query

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25761593/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 11:00:48  来源:igfitidea点击:

WP_Query with “post_title LIKE 'something%'” and category

wordpress

提问by jignesh886660

I need to do a WP_Query with a LIKE on the post_title and category

我需要在 post_title 和 category 上用 LIKE 做一个 WP_Query

This query_post is not working

此 query_post 不起作用

query_posts(
     array(
        'post_type' => 'add_buying',
        'like' => $keywords,
        'posts_per_page' => 5,
        'taxonomy' => 'add_country',
        'term' => 'drawing'
 ));

回答by Dharmik

Check this urland change the likeparameter.

检查此 url并更改like参数。

query_posts( array(
'post_type' => 'add_buying',
's' => $keywords,
'posts_per_page' => 5,
'taxonomy' => 'add_country',
'term' => 'drawing' 
));

回答by MISSIRIA

Change your second parameter to 's' and I think it's going to work:

将您的第二个参数更改为 's',我认为它会起作用:

$args = array(      
    'post_type'   => 'post',
    's'           => $search_term,
    'post_status' => 'publish'    
);
$wp_query = new WP_Query($args);

And good luck

还有祝你好运

回答by MISSIRIA

title (string) - use post title (available with Version 4.4).

title (string) - 使用帖子标题(在 4.4 版中可用)。

$args = array(      
    'post_type'   => 'post',
    'title'       => $title,
    'post_status' => 'publish'
); 
$wp_query = new WP_Query($args);