查找具有完全相同标题的其他产品



以下代码获取我需要的产品,但它与确切的磁贴(名称(不匹配,因此有时它会得到一些不需要的产品。

$pname = $product->get_name();
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'posts_per_page' => '5',
'order' => 'asc',
"s" => $pname,
'tax_query' => array(
array(
'taxonomy' => 'product_type',
'field' => 'slug',
'terms' => 'bundle',) )
);
$products = new WP_Query($args);

现在,如果我向其添加"meta_qury",它根本不起作用,页面显示错误。

$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'posts_per_page' => '5',
'order' => 'asc',
"s" => $pname,
'tax_query' => array(
array(
'taxonomy' => 'product_type',
'field' => 'slug',
'terms' => 'bundle',) )
'meta_query' => array(
array(
'key' => 'title',
'value' => $pname,
'compare' => '=') )
);

有人可以帮我解决这个问题吗?我是WordPress和PHP的新手。

这很简单,只是改变

"s" => $pname,

'title' => $pname,

在原始代码中没有添加任何"meta_query"解决了这个问题。

相关内容

最新更新