WordPress: Display Custom Post Types On Category Pages

Custom post types are an additional “type” of “post” and are very handy if you need to create an extra section on your website. There can be some issues in display posts on a category page for a given custom post type. Copy and paste the following code into your theme’s functions.php file to enable custom post type’s on category pages:

function ve_products_sql_where_clause($sql) {
  if (is_category()) {
    $sql = str_replace("wp_posts.post_type = 'post'", "wp_posts.post_type = 've_products'", $sql); 
  }
  return $sql;
}
add_filter('posts_where', 've_products_sql_where_clause');
Free Graphics, Icons, Tutorials
Free Graphics Free Christmas Vector Icon Graphics Pack 2017Free Fitness Vector Icons Graphics PackFree Camping Vector Graphics PackFree Summer Graphics PackFree File Icon PackFree Fast Food Vector Graphics
Sharing is caring...
Like & Follow
Share the love, share this page! Facebook Twitter Google Digg Reddit LinkedIn Pinterest Email
Close [X]
The Web Taylor
1000 Lakeside North Harbour Portsmouth, Hampshire PO6 3EN
02392 123358