从自定义分类法中获取帖子 [英] Get Posts from custom taxanomy

查看:25
本文介绍了从自定义分类法中获取帖子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获取自定义分类的帖子,您可以查看下面的代码 ppctrainings 是自定义分类类别,94 是类别的 id.

I want to get posts with custom taxonomy, you can check the code below ppctrainings is the custom taxonomy category and 94 is the id of category.

<?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++;
?>

推荐答案

<?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();
?>

这篇关于从自定义分类法中获取帖子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆