Woocommerce Meta_Query for Hidden Products -
i'm using theme has custom product loop on home page. great except "hidden" products showing on home page. provide bit of code fix it, keep getting parse errors.
current code index.php:
<?php if (of_get_option("cap_show_merch") == true){?> <?php //woocommerce check ?> <?php if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) { ?> <h2><?php echo of_get_option("cap_merch_title"); ?></h2> <div class="preview-block"> <?php global $product; $num = 0; $merch = new wp_query( array( 'posts_per_page' => 5, 'post_type' => array( 'product' ) ) ); if( $merch->have_posts() ) : while( $merch->have_posts() ) : $merch->the_post(); $product = get_product(); if ( $num == 0 ) : ?> <div class="preview"> <div class="visual"> <?php if ( has_post_thumbnail() ) : ?> <img src="<?php echo aq_resize( wp_get_attachment_url( get_post_thumbnail_id(), 'full' ), 473, 453, true ); ?>" width="473" height="453" alt="<?php the_title(); ?>" /> <?php else : ?> <img src="<?php echo woocommerce_placeholder_img_src(); ?>" alt="placeholder" /> <?php endif; ?> <a href="<?php the_permalink(); ?>" class="mask"></a> <?php woocommerce_template_loop_price(); ?> </div> <a href="<?php the_permalink(); ?>" class="caption"><?php the_title(); ?></a> </div> <?php else : ?> <?php if ( $num == 1 ) : ?> <ul class="catalog"> <?php endif; ?> <li> <div class="visual"> <?php if ( has_post_thumbnail() ) : ?> <img src="<?php echo aq_resize( wp_get_attachment_url( get_post_thumbnail_id(), 'full' ), 222, 193, true ); ?>" width="222" height="193" alt="<?php the_title(); ?>" /> <?php else : ?> <img src="<?php echo woocommerce_placeholder_img_src(); ?>" alt="placeholder" /> <?php endif; ?> <a href="<?php the_permalink(); ?>" class="mask"></a> <?php woocommerce_template_loop_price(); ?> </div> <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> </li> <?php endif; $num++; endwhile; ?> </ul> <?php endif; wp_reset_postdata(); ?> </div><!--preview-block--> <?php } //woocommerce check?> <?php } ?>
i asked in wordpress forums here, , provided code james koster.
'meta_query' => array( array( 'key' => '_visibility', 'value' => array( 'catalog', 'visible' ), 'compare' => 'in' ) )
when added php under "'post_type' => array( 'product' )" looks this;
<?php global $product; $num = 0; $merch = new wp_query( array( 'posts_per_page' => 5, 'post_type' => array( 'product' ) 'meta_query' => array( array( 'key' => '_visibility', 'value' => array( 'catalog', 'visible' ), 'compare' => 'in' ))));
but returns error;
"parse error: syntax error, unexpected t_constant_encapsed_string, expecting ')' in/.../themes/destinlive/index.php on line 116".
line 116 "'meta_query' => array("
i'm not @ proficient in php, , lack of detail james put it, (i'm thankful help) has left me spending several hours trying different configurations no avail. i'm turning here help.
thank in advance generous help.
you're missing comma after 'post_type' => array( 'product' )
Comments
Post a Comment