【问题标题】:Use meta value as taxonomy term in Wordpress query在 Wordpress 查询中使用元值作为分类术语
【发布时间】:2015-02-18 20:45:33
【问题描述】:

我需要使用自定义元动态更改分类术语。下面是我开始的地方......对我来说很有意义,但不起作用。

<?php
$dynamic = rwmb_meta( $post->ID, blr_queryslug, true );


$args = array(
'posts_per_page' => -1,
'tax_query' => array(
    'relation' => 'AND',
    array(
        'taxonomy' => 'product_cat',
        'field' => 'slug',
        'terms' => 'music'
    ),
    array(
        'taxonomy' => 'product_cat',
        'field' => 'slug',
        'terms' => '$dynamic'
    )
    ),
    'post_type' => 'product'
  );
$the_query = new WP_Query( $args );
// The Loop
while ( $the_query->have_posts() ) {
$the_query->the_post();
woocommerce_get_template_part( 'content', 'product' );
}
wp_reset_postdata();
?>

【问题讨论】:

    标签: wordpress meta taxonomy taxonomy-terms


    【解决方案1】:

    改变

        'terms' => '$dynamic'
    

        'terms' => $dynamic
    

    PHP 不会替换单引号内的变量。

    【讨论】:

    • 非常感谢你!那一直在杀死我。答案很简单:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-01-04
    • 2021-10-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-13
    相关资源
    最近更新 更多