I have a list of articles on my website.
Some of the articles are post types with the "Article" category and others are PDF files uploaded to the media library, also with the "Article" category. I added categories to the media library using these functions in functions.php:
// add categories for attachments
function add_categories_for_attachments() {
register_taxonomy_for_object_type( 'category', 'attachment' );
}
add_action( 'init' , 'add_categories_for_attachments' );
// add tags for attachments
function add_tags_for_attachments() {
register_taxonomy_for_object_type( 'post_tag', 'attachment' );
}
add_action( 'init' , 'add_tags_for_attachments' );
thanks to this article.
I need to display a single category page which lists both types of posts (media and regular posts).
Is there a simple way to achieve it?
I have a list of articles on my website.
Some of the articles are post types with the "Article" category and others are PDF files uploaded to the media library, also with the "Article" category. I added categories to the media library using these functions in functions.php:
// add categories for attachments
function add_categories_for_attachments() {
register_taxonomy_for_object_type( 'category', 'attachment' );
}
add_action( 'init' , 'add_categories_for_attachments' );
// add tags for attachments
function add_tags_for_attachments() {
register_taxonomy_for_object_type( 'post_tag', 'attachment' );
}
add_action( 'init' , 'add_tags_for_attachments' );
thanks to this article.
I need to display a single category page which lists both types of posts (media and regular posts).
Is there a simple way to achieve it?
Share Improve this question asked Jun 9, 2019 at 13:49 CaptainNemoCaptainNemo 1054 bronze badges2 Answers
Reset to default 1Something like this should work :
$args = array ( 'post_type' => array( 'post', 'attachment'), 'category' => ARTICLE_CATID );
$query = new WP_Query( $args );
Thanks to @bjornredemption, I used the following code snippet:
$args = array('category' => $wp_query->get_queried_object_id(), 'posts_per_page' => -1, 'orderby'=> 'title', 'order' => 'ASC', 'post_type' => array( 'post', 'attachment'),'post_status' => array( 'publish', 'inherit'));
$glossaryposts = get_posts( $args );
Furthermore the function have_posts() must be changed because the default one does not check for attachments.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745406236a4626326.html
评论列表(0条)