从自定义分类中获取帖子

时间:2014-06-23 04:53:10

标签: wordpress taxonomy

我想获得带有自定义分类的帖子,您可以查看下面的代码,ppctrainings是自定义分类法类别,94是类别ID。

<?php 
$count = 0;
// this is the custom taxonamy ppctrainings the id is 94
$posts = get_posts('ppctrainings=94&numberposts=10'); 
foreach($posts as $post) { 
if($count == 3){
echo '</tr><tr >';
$count = 0; 
}
$count++;
?>

3 个答案:

答案 0 :(得分:0)

<?php
$args = array(
    'tax_query' => array(
        array(
            'taxonomy' => 'sliders_category', // taxonomy category
            'field' => 'id',
            'terms' => '2' // category id
        )
    ),
    'post_type'=>'sliders',  //name of post type 
    'order'=>'ASC',
    'posts_per_page'=>10
);
    query_posts($args);
    while ( have_posts() ) : the_post(); 
?>

 // your code for display  title and content

<?php   
    endwhile; 
    wp_reset_query();
?>

答案 1 :(得分:0)

使用以下代码获取自定义帖子类型数据。

$args = array(
'posts_per_page' => '-1',
'post_type' => 'blog',
'post_status' => 'publish',
'order' => 'ASC',
'orderby' => 'post_date');

$the_query = new WP_Query($args);

while ($the_query->have_posts()) {
                        $the_query->the_post();
    // Write your code here
}

答案 2 :(得分:0)

您可以通过多种方式查询WordPress数据库