2017-09-26 2 views
1

나는 워드 프레스 테마를 개발 중이며 '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(); 
    } 

    ?> 

내가 누락 된 부분을 아는 사람이 있습니까?

+0

Wordpress 기본 게시물 유형 및 카테고리에서 데이터를 가져 오는 중입니까? –

답변

0

사용되는 카테고리 ID를 사용하지 카테고리 이름

$category_id=1; 

    $custom_query = new WP_Query([ 
      'post_type' => 'post','posts_per_page' => -1,'order' => 'ASC','cat' => $category_id 
     ]); 
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

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); ?> 
관련 문제