问题
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++;
?>
回答1:
<?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();
?>
回答2:
Use the below code for getting the custom post type data.
$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
}
回答3:
There are many ways you can query the WordPress database
- pre_get_posts action
- query_posts()
- the WP_Query
来源:https://stackoverflow.com/questions/24358582/get-posts-from-custom-taxanomy