如何在WP_Query中搜索帖子标题,内容和帖子元?

时间:2016-11-22 11:18:37

标签: php wordpress

我有一个搜索条件,我需要搜索post_title,post_content或post_meta,称为' description'。在保存帖子时:

  $post = array(
            'post_title'    => $title,
            'post_status'   => 'publish', 
            'post_type' => "courses"  
            );
  $id = wp_insert_post($post);
  update_post_meta($id, 'description', $description);

在搜索帖子时,我使用以下代码:

  if($_GET['tewa_search'] != ''){

        $keyword = $_GET['tewa_search'];
        $the_query = new WP_Query(array(
        'post_type' => 'courses',
        array('s'=> $keyword),
        'meta_query' => array (
            'relation' => 'OR',
                array (
                  'key' => 'inistitute_name',
                  'value' => array ($institute_name),
                  'compare' => 'IN'
                ),
                array (
                  'key' => 'description',
                  'value' => $keyword,
                  'compare' => 'LIKE'
                )
            ),
        'posts_per_page' => '5',
        'paged' => $paged,
        'post_status' => array('publish', 'pending', 'draft'),
        'order' => 'DESC'
        )); 

    }

目前只有帖子标题工作正常,但如果我搜索post_meta"描述"然后它不工作。任何人都可以告诉我,我做错了什么?

0 个答案:

没有答案