WP_Query带有"post_title LIKE'某事'%'"和类别

jig*_*660 2 wordpress

我需要在post_title和类别上使用LIKE执行WP_Query

此query_post无效

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

Dha*_*mik 6

检查此网址并更改like参数.

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

  • 就像旁注一样,这也会在帖子的内容中进行搜索. (2认同)

小智 5

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

$args = array(      
    'post_type'   => 'post',
    's'           => $search_term,
    'post_status' => 'publish'    
);
$wp_query = new WP_Query($args);
Run Code Online (Sandbox Code Playgroud)

还有祝你好运