最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

wp query - wp_query with meta_query and tax_query

programmeradmin2浏览0评论

I am trying to find a way to combine a meta_query and a term_query and i got confused with the research.

    $sport = 'basket';
    $args_p = array(
                    'posts_per_page'      => 10,
                    'post_type' => 'user',
                    'no_found_rows'       => true,
                    'post_status'         => 'publish',
                    'meta_key' => 'user_overall_rating',
                    'tax_query' => array(
                              array(
                                  'taxonomy'  => 'restricted-sport',
                                  'field'     => 'slug',
                                  'terms'     => array($sport)
                                   'operator'  => 'NOT IN')    
                    ),
                    'orderby'  => 'meta_value_num',
                    'order'    => 'DESC'
                );
                $r = new WP_Query( apply_filters( 'widget_posts_args',$args_p  ) );
if (r->have_posts()):...

So i want to filter and get the top 10 users that does not have '$sport' basket as restricted sport. There are post_types that have taxonomies 'basket' ,'soccer' etc so i expected to get 10 top from the rest sports, but i get an error :) PHP Fatal error: Uncaught Error: Call to a member function have_posts() on null in widget-5.php "r->have_posts()"

发布评论

评论列表(0)

  1. 暂无评论