Skip to content

Instantly share code, notes, and snippets.

@shangdev
Last active June 23, 2017 09:42
Show Gist options
  • Save shangdev/2e57d2fba974eccf32db13db083dd576 to your computer and use it in GitHub Desktop.
Save shangdev/2e57d2fba974eccf32db13db083dd576 to your computer and use it in GitHub Desktop.
wordpress:根据自定义分类获取产品
<?php
global $post;
$args = array(
'posts_per_page' => 1,
'post_type' => 'product',
'tax_query' => array(
array(
'taxonomy' => 'product_cat',
'field' => 'term_id',
'terms' => $item->term_id,
'operator' => 'IN'
)
)
);
$cat_posts = get_posts( $args );
// var_dump($cat_posts);
foreach ( $cat_posts as $post ) : setup_postdata( $post ); ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment