2017-09-26 16 views
1

私はWordpressのテーマを開発していて、特定のCatagory(Artikel)で投稿を表示したいと考えています。しかし、私のコードは動作していません。これは私のコードです:投稿をどのようにフィルタリングするのですか?

<?php 
    $custom_query = new WP_Query([ 
     'cat' => 'Artikel', 
    ]); 
    if ($custom_query->have_posts()) { 
     while ($custom_query->have_posts()) { 
     $custom_query->the_post(); ?> 


     /* do things */ 

     <?php 

     } 
     wp_reset_postdata(); 
    } 

    ?> 

誰かが私に欠けていることを知っていますか?

$category_id=1; 

    $custom_query = new WP_Query([ 
      'post_type' => 'post','posts_per_page' => -1,'order' => 'ASC','cat' => $category_id 
     ]); 
+0

wordpressのデフォルトの投稿タイプとカテゴリからデータを取得していますか? –

答えて

0

私はこのようにそれを行うだろう:

<?php 
$args = array(
       post_type => 'post', 
       'category_name' => 'Artikel', 
       'posts_per_page' => 3, 
       'orderby' => 'date', 
       'order' => 'ASC' 
      ); 
    $custom_query = new WP_Query($args); 

    if ($custom_query->have_posts()) { 
     while ($custom_query->have_posts()) { 
     $custom_query->the_post(); 

[etc.] 
    ?> 
0

カテゴリID使用されていないカテゴリ名を使用

+0

not working ..何も表示されません –

0

特定のカテゴリからの投稿を表示するには、このコードを使用してください。

<?php $args = array(
    'post_type' => 'post', 
    'post_status' => 'publish', 
    'posts_per_page' =>'4', 
    'tax_query' => array(
     array(
      'taxonomy' => 'category', 
      'field' => 'name',  
      'terms' => 'Artikel' 
     ), 
    ), 
); 
$the_query = new WP_Query($args); ?> 
関連する問題