在搜索结果中,我很难将产品和页面分开。
到目前为止,这就是我所拥有的
<?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; ?>我已经到了让产品结果以我想要的方式显示的地步(所以它们都显示在默认的woocommerce布局中)。但我似乎不能将产品排除在“页面”结果之外。也就是说,所有的产品也会出现在页面结果上。
示例:
产品结果
产品1-产品2-产品3-产品4
页面结果
第1页(产品1,见上文)
第2页(产品2,见上文)
第3页(产品1,如上所示)
第4页(产品2,见上文)
我希望
if ( $post->post_type == 'page' )只返回实际页面(不返回产品)。但没有运气。
因此,我的问题是,作为标题声明,我如何区分实际页面和产品与woocommerce在wordpress中的搜索结果?
发布于 2016-10-26 14:50:08
您需要这样的东西在您的页面之前,而have_posts
<?php
global $wp_query;
$args = array_merge( $wp_query->query_vars, array( 'post_type' => 'page' ) );
query_posts( $args );
while ( have_posts() ) : the_post(); ?>https://stackoverflow.com/questions/40263801
复制相似问题