【发布时间】:2018-08-24 13:01:10
【问题描述】:
我想通过产品的标题或名称(slug)查询产品。下面的代码将允许我检索具有特定标签的产品,但是当我尝试使用 page 或 pagename 而不是 product_tag 时,不会返回任何产品。除非我忽略了它,否则我没有看到相关的product_page 或类似的可用。感谢您深入了解我可能出错的地方。
function woo_products_by_name_shortcode( $atts, $content = null ) {
// Get attributes
extract(shortcode_atts(array( "tags" => '' ), $atts));
ob_start();
// Define Query Arguments
$args = array(
//'post_type' => array('product','product_variation'),
'post_type' => 'product',
'posts_per_page' => 5,
'product_tag' => $tags
);
// Create the new query
$loop = new WP_Query( $args );
// Get products number
$product_count = $loop->post_count;
// If results
if( $product_count > 0 ) :
【问题讨论】:
标签: php wordpress woocommerce shortcode product