I created a custom plugin which creates a custom post type live-blog. Now i am using

add_filter('pre_get_posts', 'query_post_type');
function query_post_type($query) {
  if( is_category() ) {
    // print_r("HI"); die;
    $post_type = get_query_var('post_type');
    // print_r($post_type); die;
        $post_type = $post_type;
        $post_type = array( 'post', 'live-blog');
    return $query;

this code to show my custom post type on category pages but it is ruining my rss feed. For example when i am adding a live blog into my category A it works really well but when i check the rss feed for the same category. It shows description and content only for the post type which is last published. Let say i have 5 live blogs and 5 posts in one category now when i publish new post and check the rss feed it shows data for post correctly but the description and content for live blog gets empty and its same in case of live blog as well.

How can i fix my rss feed and show the both custm post type in category feed.

  • 1
    FYI pre_get_posts is an action, not a filter: change add_filter to add_action, and remove the return $query. Also, the is_category() and get_query_var() uses should be specific to the current query (and not the global query): $query->is_category() and $query->get().
    – Caleb
    Jun 26, 2023 at 16:28


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.