2015-09-07 104 views

回答

1

您不需要使用SELECT在分类学slu help的帮助下获取自定义文章。

WordPress为我们提供了get_posts函数来检索符合给定条件的帖子列表。

$posts_array = get_posts(
    array(
     'posts_per_page' => -1, //-1 is to retrieve all posts. 
     'post_type' => 'my_custom_post', //specify your custom post. 
     'tax_query' => array(
      array(
       'taxonomy' => 'my_taxonomy' //taxonomy on which you are going to find posts 
      ) 
     ) 
    ) 
); 
0

您必须使用WP_Query来获取所需的帖子。在你的情况下,查询可能是这样的:

<?php 
    $the_query = new WP_Query(array(
     'post_type' => 'my_custom_post', 
     'tax_query' => array(
      'taxonomy' => 'my_custom_taxonomy', 
      'field' => 'slug', 
      'terms' => 'my_custom_taxonomy_slug', 
     ), 
    )); 

    while ($the_query->have_posts()) : 
     $the_query->the_post(); 
     // Show Posts ... 
    endwhile; 

    /* Restore original Post Data */ 
    wp_reset_postdata(); 
?> 

Click here要阅读它的文档。