admin管理员组文章数量:1302383
I'm building a child theme and have set up an additional custom post type ('blogs').
I need regular and custom posts to be returned on the archive page. The have_posts function only returns regular posts.
How do I amend the have_posts function to include custom posts?
<?php if ( have_posts() ) :
while ( have_posts() ) :
the_post();
endwhile; wp_reset_postdata();
endif;
?>
I did try this approach:
<?php
$args = array(
'post_type' => array( 'post', 'blogs' ),
);
$myQuery = new WP_Query($args);
if ($myQuery->have_posts() ) :
while ($myQuery->have_posts() ) :
$myQuery->the_post();
endwhile; wp_reset_postdata();
endif;
?>
Which returned posts and 'blogs' - but from ALL categories, instead of posts and 'blogs' with the relevant category.
Any advice would be much appreciated as I'm new to Wordpress dev.
本文标签: child themeHow do I amend the haveposts function to include custom posts
版权声明:本文标题:child theme - How do I amend the have_posts function to include custom posts? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741692793a2392830.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论