1

I am trying to solve this problem:

I created new custom post types. When I create a post and assign a category (lets say category-1) to it, and when I try to visit the category-1 url, it appears "There has been an error."

I tried solving the issue based on the Michal Mau post (How to display regular posts & custom post types that fall under a category using just the generic category template?).

My edited code after adding Michal Mau suggestion looks like this:

<?php if (have_posts()) :
global $wp_query;
$args = array_merge( $wp_query->query, array( 'post_type' => 'any' ) );
query_posts( $args );

while (have_posts()) : the_post(); ?>
  <article id="post-<?php the_ID(); ?>" <?php post_class('post-holder'); ?>>
    <?php if(has_post_thumbnail()) {
                echo '<figure class="featured-thumbnail"><span class="img-wrap"><a href="'; the_permalink(); echo '">';
                echo the_post_thumbnail();
                echo '</a></span></figure>';
                }
            ?>

The problem wasn't solved. I don't know if there is a mistake pasting the code or any other mistake.

  • This may sound stupid. I always people click save button a few times on permalink structure setting first if they have problems with cpt. – Jesse Mar 8 '13 at 12:10
1

The query_posts solution is not reccomended (see you don't know query). You should use pre_get_posts hook instead. See:

function my_extend_category_by_custom_post_type( $query ) {
    if ( $query->is_category() && $query->is_main_query() ) {
        $query->set( 'post_type', 'any' );
    }
}
add_action( 'pre_get_posts', 'my_extend_category_by_custom_post_type' );

PS: this should go into your functions.php if (custom post type is set from there) or, preferably, from site specific plugin.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.