I'm having some trouble separating products and pages in the search results.
This is what I have so far
<?php if ( have_posts() ) : ?>
<?php if ( $post->post_type == 'product' ) : ?>
<div class="woocommerce">
<h2>Product results</h2>
<ul class="products cols-4">
<?php woocommerce_product_loop_start(); ?>
<?php woocommerce_product_subcategories(); ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php wc_get_template_part( 'content', 'product' ); ?>
<?php endwhile; ?>
<?php woocommerce_product_loop_end(); ?>
</ul>
</div>
<?php endif; ?>
<?php if ( $post->post_type == 'page' ) : ?>
<h2>Page results</h2>
<?php while ( have_posts() ) : the_post(); ?>
<?php x_get_view( $stack, 'content', get_post_format() ); ?>
<?php endwhile; ?>
<?php endif; ?>
<?php else : ?>
<?php x_get_view( 'global', '_content-none' ); ?>
<?php endif; ?>
I've gotten to the point where I get product results to show up the way I want (so they all show as in the default woocommerce layout). But I can't seem to exclude products from the "page" results. I.e. all the products show up on the page results as well.
Example:
Product results
PRODUCT 1 - PRODUCT 2 - PRODUCT 3 - PRODUCT 4
Page results
PAGE 1 (product 1, already shown above)
PAGE 2 (product 2, already shown above)
PAGE 3 (product 1, already shown above)
PAGE 4 (product 2, already shown above)
I was hoping that
if ( $post->post_type == 'page' )
would only return actual pages (not products). But no luck.
So my question is as the title states, how do I distinguish between actual pages and products from woocommerce in wordpress for the search results?