2017-12-15 4 views
2

게시물 제목의 마지막 몇 자리를 아래 코드와 쉼표로 구분 된 값으로 표시하려고합니다. 여기에서 wp_post 테이블에서 쿼리를 만들고 있습니다. 어떻게이 코드에서 카테고리를 얻을 수 있습니까? category에 대한 열은 wp_post 테이블에 없습니다. 아래에있는 내 코드Wordpress 게시판에서 카테고리 가져 오기

<?php 
     $posts = $wpdb->get_col(" 
     SELECT $wpdb->posts.* 
     FROM $wpdb->posts 
     WHERE post_status = 'publish' 
     and post_type='post' 

     ORDER BY post_date DESC LIMIT 10"); 

     $the_posts = array(); 
     foreach($posts as $post) : 
     echo implode(', ', $the_posts); 
    ?> 
+0

csv는 어디에 있습니까? – Strawberry

답변

1

입니다 당신은 이런 식으로 할 수 있습니다 : - (WP에 대한 올바른 방법을) 게시물을 얻을

<?php 
    $args = array(
    'posts_per_page' => 10, 
    'orderby'   => 'date', 
    'order'   => 'DESC', 
    'post_type'  => 'post', 
    'post_status'  => 'publish', 
    'suppress_filters' => true 
); 
$posts_array = get_posts($args); ?> 

2 -

1 루프 게시물 및 카테고리 얻을

foreach($posts_array as $post):setup_postdata($post); 
    $category = get_the_category(); 
    var_dump($category); 
endforeach; 
wp_reset_postdata(); 
+0

예기치 않은 '$ category' – Mithu

+0

의 구문 오류가 발생했습니다. after setup_postdata ($ post) –

+0

코드 –

관련 문제