簡體   English   中英

如何在Wordpress中使用多關系分類法查詢創建循環

[英]how to create loops with multi relation taxanomy queries in wordpress

我正在嘗試創建一個循環,以加載來自自定義分類法和特定類別的帖子,我在下面使用了此代碼,但未顯示任何內容

<ul class="row">
    <?php 
        $latest_apps = new WP_Query(array(
            'post_type' => array('product','post'),
            'posts_per_page' => 30,
            'tax_query' => array(
                    'relation' => 'AND',
                    array(
                        'taxonomy' => 'category',
                        'field' => 'id',
                        'terms' => array( get_option("free_apps_category") )
                    ),
                    array(
                        'taxonomy' => 'product_cat',
                        'field' => 'id',
                        'terms' => array( get_option("premium_apps_category") )
                    )
            )
        ));
        $c = 0;
        while ($latest_apps->have_posts()) : $latest_apps->the_post();
        $c++;

        // post is even
        if( $c % 2 == 0) {
            ?>
                <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" data-titty="<?php the_title(); ?>"><?php the_post_thumbnail("post"); ?></a>
            </li>
            <?php
        }

        // post is odd
        else {

        ?>
            <li class="content-box-post">
                <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" data-titty="<?php the_title(); ?>"><?php the_post_thumbnail("post"); ?></a>
        <?php
        }
        endwhile;
    ?>
    </ul>

我已經使用了靜態ID號代替了get_option('free_apps_category')和get_option('premium_apps_category'),但是仍然無法正常工作,請幫忙,謝謝

如果沒有顯示任何內容,那是因為您沒有符合您條件的帖子。 並快速閱讀代碼,您可以看到您的查詢是針對在premium_apps_categoryfree_apps_category上屬於普通帖子還是product帖子類型的free_apps_category 您確定您確實有一個嗎?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM