2016-06-29 72 views
0

我正在寻找所有包含某个特定名称的帖子,而我拥有的代码是一半的工作。它通过标准帖子,但不知道如何让它显示所有的自定义帖子类型。通过标题获得类似帖子?

这里是在functions.php的

add_filter('posts_where', 'wpse18703_posts_where', 10, 2); 
function wpse18703_posts_where($where, &$wp_query) 
{ 
    global $wpdb; 
    if ($wpse18703_title = $wp_query->get('wpse18703_title')) { 
     $where .= ' AND ' . $wpdb->posts . '.post_title LIKE \'' . esc_sql($wpdb->esc_like($wpse18703_title)) . '%\''; 
    } 
    return $where; 
} 

代码这里是一个然后使用该功能查找该名称的职位代码。

<div class="main-content large-8 medium-8 small-12 columns"> 
     <h2><?php the_title(); ?> News and Features</h2> 
     <?php 
     $title = $wp_query->post->post_title; 
     $query = new WP_Query(
      array(
      'wpse18703_title' => "$title", 
      'posts_per_page' => 10, 
      'post__not_in' => array($post->ID), 
       'post_type' => array('post', 'it_review') 
      ) 
     ); 

     if ($query->have_posts()){ 
      while ($query->have_posts()) { $query->the_post(); ?> 
       <div class="small-12 large-12 gdb-news-container"> 
       <div class="small-12 large-4 columns gdb-news-image"> 
        <?php the_post_thumbnail(); ?> 
       </div> 
       <div class="small-12 large-8 columns"> 
        <h3><?php the_title(); ?></h3> 
       <?php echo content(20); ?> 
       </div> 
        <div class="clearfix"></div> 
       </div> 

我的理想场景是仅使用游戏的标题,例如辐射4,它显示标题中包含该标题的所有帖子。

回答

0

用一双新鲜的眼睛回顾我的代码,我注意到我没有在'post_type'=>数组('')中输入正确的帖子类型。

包括正确的帖子类型后,它也开始拉动这些帖子。

以为我会回答这个情况,以防其他人像我一样想念它。