Skip to content
  • home
  • portfolio
  • web design journal
  • blog
    • adventure
    • san diego
    • projects
    • website design
Blog Web Dev

WordPress – Category Page Not Showing Posts With Custom Post Type

By Forrest Smith - Drempd.com

I had created a post type for news articles. Unfortunately, when categorizing the pages, and trying to view the category from the front end, those posts weren't appearing.   Apparently that doesn't work for cusotm post types by default. To get them to show, add this to the functions.php file:

function namespace_add_custom_types( $query ) {
   if( (is_category() || is_tag()) && $query->is_archive() && empty( $query->query_vars['suppress_filters'] ) ) {
      $query->set( 'post_type', array(
       'post', 'news'
      ));
   }
}
add_action( 'pre_get_posts', 'namespace_add_custom_types' );

Posted on May 25, 2022August 26, 2022 in Web Dev
  • Adventure

    • adventure
    • gravelgrinding
    • hiking
    • running
  • The Built Environment

    • architecture
    • urbanity
  • Locations

    • san diego
    • portland
  • Freelance Life

    • freelancing
    • productivity
  • Web Dev

    • css
    • entrepreneurship
    • git
    • handlebars
    • html
    • inkscape
    • photoshop
    • php
    • sass
    • web design
    • web development
    • saphire

drempd | san diego, ca


home contact

adventures san diego urbanity and architecture projects stream website design

portfolio resume san diego web design freelance web designer

custom web design responsive web design website maintenance