Kelvin Jayanoris
Kelvin Jayanoris

Reputation: 37

Custom Post Types on Category Pages

I am using this bit of code to make custom post typess show on my category pages:

<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts(array( 'post_type' => 've_products', // custom post type 'paged'=>$paged, )); ?>

Is there a way I can modify this code to include it into functions.php instead of category.php and achieve the same effect?

Thanks!

Upvotes: 1

Views: 6150

Answers (1)

Richard M
Richard M

Reputation: 14543

You should be able to add a posts_where filter to achieve the same effect, something like this:

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');

Upvotes: 1

Related Questions