簡體   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