Php 是否显示按分类法分组的自定义文章类型的摘录、缩略图和标题?
例如,我想显示一个带有自定义帖子类型和特定分类法的所有帖子的标题 我尝试了以下几点:Php 是否显示按分类法分组的自定义文章类型的摘录、缩略图和标题?,php,wordpress,Php,Wordpress,例如,我想显示一个带有自定义帖子类型和特定分类法的所有帖子的标题 我尝试了以下几点: global $post; $myposts = get_posts(array( 'post_type' => 'my-post-type', 'tax_query' => array( array( 'taxonomy' => 'post-type-category', 'terms' => 'new-
global $post;
$myposts = get_posts(array(
'post_type' => 'my-post-type',
'tax_query' => array(
array(
'taxonomy' => 'post-type-category',
'terms' => 'new-posts')
)
)
);
foreach ($myposts as $mypost) {
echo $mypost->post_title;
}
您可以使用:
<?php
$args = array(
'post_type' => 'my-post-type',
'tax_query' => array(
array(
'taxonomy' => 'post-type-category',
'field' => 'slug',
'terms' => 'new-posts',
),
),
);
// The Query
$the_query = new WP_Query( $args );
// The Loop
if ( $the_query->have_posts() ) {
while ( $the_query->have_posts() ) {
$the_query->the_post();
the_title() ; // title
the_excerpt(); // excerpt
the_post_thumbnail(); // post thumbnail
}
wp_reset_postdata();
} else {
// no posts found
}