2016-06-29 7 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を 'post_type' =>配列( '')に入れていないことに気付きました。

正しいポストタイプを入力した後、ポストも引き継ぎます。

私は誰かが私のようにそれを見逃している場合に私はこれに答えるだろう。

関連する問題