简体   繁体   English

如何在Wordpress中使用多关系分类法查询创建循环

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

I'm trying to create a loop that loads posts from a custom taxonomy and a specific category , i have used this code below but it doesn't show anything 我正在尝试创建一个循环,以加载来自自定义分类法和特定类别的帖子,我在下面使用了此代码,但未显示任何内容

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

i have used static id numbers instead of get_option('free_apps_category') and get_option('premium_apps_category') but it still does not work please help , thank u so much regards 我已经使用了静态ID号代替了get_option('free_apps_category')和get_option('premium_apps_category'),但是仍然无法正常工作,请帮忙,谢谢

If it does not show you nothing, it is because you have no posts that match your condition. 如果没有显示任何内容,那是因为您没有符合您条件的帖子。 And reading the code fast One can see that your query is for a post either normal or under product post type that is both on the premium_apps_category AND free_apps_category . 并快速阅读代码,您可以看到您的查询是针对在premium_apps_categoryfree_apps_category上属于普通帖子还是product帖子类型的free_apps_category Are you sure that you actually have one ? 您确定您确实有一个吗?

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

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