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