Site logo

Archived topic

Custom post type on archive pages with GeneratePress

3 replies · Started by David on April 3, 2023

Viewing posts 1–4 of 4

Hey guys,

I'm adding a custom post type to the archive pages with:

public function add_products_to_archives( $query ) {
  if( is_category() || is_tag() && empty( $query->query_vars['suppress_filters'] ) ) {
    $query->set( 'post_type', array(
      'post', 'gp_elements', 'nav_menu_item', 'products'
    ));
  return $query;
  }
}

This works, but removes the wrapper and classes that GeneratePress otherwise adds around and to the articles.

This is your usual code:

<main class="site-main" id="main">
  <div class="generate-columns-container ">
    <header class="page-header" aria-label="Page"> ... </header>
	<article id="post-9505" class="post-9505 post type-post status-publish format-standard has-post-thumbnail hentry category-gear generate-columns tablet-grid-50 mobile-grid-100 grid-parent grid-33 resize-featured-image"> ... </article>
	<article ...
</div><!-- .generate-columns-contaier -->
</main>

It becomes:

<main class="site-main" id="main">
  <header class="page-header" aria-label="Page"> ... </header>
  <article id="post-10154" class="post-10154 products type-products status-publish hentry category-inflatable product_tag-inflatable">...</article>
  <article ...
</main>

The wrapper div and extra classes are gone.

Can you help me out?

Thanks,
David

Thanks David, that works!

Glad to hear that

This archived topic is closed to new replies.