繁体   English   中英

显示在Wordpress wp_query中具有两个分类法的帖子

[英]Display posts that have two taxonomies in Wordpress wp_query

我希望显示帖子是否匹配两个单独的分类法,这是免费的新娘配饰和格拉斯哥。

目前,我可以获取下面的wp_query循环代码,以显示两种分类法的所有结果。 但是,我需要循环以仅显示同时选择了两个类别的帖子。

<?php
    /**
     * Create a new WP_Query
     * Set $wp_query object to temp
     * Grab $paged variable so pagination works
     */
    ?>
    <?php
        global $wp_query; $post; $post_id = $post-> ID;
        $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
        rewind_posts();
        $temp = $wp_query;
        $wp_query = NULL;

        $post_type = 'place'; // change this to the post type you want to show
        $show_posts = '30'; // change this to how many posts you want to show
        $category_name = 'bridal-accessories-free,special-offer' // change this to the category name you need

    ?>

    <?php $wp_query = new WP_Query( 'placecategory=' . $category_name . '&post_type=' . $post_type .  '&posts_per_page=' . $show_posts . '&paged=' . $paged ); ?>
        <?php while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
            <p style="font-size: 15px; margin-bottom: 10px;"><span style="font-weight: normal; margin-right: 5px; text-transform: uppercase; color: #a5cc8e;"><?php the_title(); ?></span> <span style="margin-right: 5px; color: #000;"><?php echo get_post_meta($post->ID,'geo_address',true);?></span> <?php $contact = stripslashes(get_post_meta($post->ID,'contact',true)); 
                    if($contact && get_option('ptthemes_contact_on_detailpage') == 'Yes') { ?><?php echo PHONE.": "; ?> <?php echo $contact;?><?php } ?>
        <?php endwhile; ?></p>
    <?php wp_reset_query(); ?>

    </div>

如果可以做到,仍然可以将循环查询变量传递到url中。 我们需要它来创建指向结果的链接。

提前致谢!

请尝试此代码

$args = array(
    'post_type' => array('post','reviews'),
    'paged' => $paged,
    'tax_query' => array(
      array(
        'taxonomy' => 'category',
        'terms' => 'android',
        'field' => 'slug'
      ),
      array(
        'taxonomy' => 'review_category',
        'terms' => 'android',
        'field' => 'slug'
      ),
    )
);
query_posts($args);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM