Support » Developing with WordPress » Display CPT in Main WP Categories

  • Is it possible to display a CPT in your main WP Categories?
    Would love a plugin to accomplish this if not an easy solution.
    TY for any input you can provide.
    Anna

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    Add to your theme’s functions.php (preferably a child theme if your theme is subject to periodic updates, or make a custom plugin):

    add_action('pre_get_posts', function( $query ) {
      if ( $query->is_main_query() && $query->is_category()) {
        $query->set('post_type', ['post', 'my_CPT_slug',]);
      }
    });

    Untested. The method is sound, there could be an inadvertent syntax error. You do need to replace my_CPT_slug with the actual CPT name it was registered as.

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.