我已经使用以下代码设置了我的自定义帖子类型“sector”
register_post_type( 'sectors',
array(
'labels' => array(
'name' => __( 'Sectors' ),
'singular_name' => __( 'sectors' ),
),
'has_archive' => true,
'hierarchical' => true,
'menu_icon' => 'dashicons-heart',
'public' => true,
'rewrite' => array( 'slug' => 'your-cpt', 'with_front' => false ),
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'revisions', 'page-attributes' ),
'taxonomies' => array( 'your-cpt-type', 'post_tag' ),
));
}
这允许我在自定义帖子类型页面中添加“标签”。
现在,我试图通过某些标签来显示这个自定义帖子类型的页面。
我已经设法通过使用以下代码来做到这一点:
$args = array('tag_slug__and' => array('featuredpost1'));
$loop = new WP_Query( $args );
while ($loop->have_posts() ) : $loop->the_post();
?>
<?php the_title(); ?>
这将获得所有标签为“featurespost1”的帖子。
如何使用自定义帖子类型?
编辑/ UPDATE:
这是现在工作,有没有办法我可以在另一个页面上使用这个功能?例如,在我的主页上通过标签获取帖子,所以本页面上更新的内容将在主页上更新?