具有多个关系的WordPress大查询AND

时间:2018-09-25 11:08:43

标签: wordpress

我正在写网站的帖子过滤器。

我的WordPress AAADAAAAAM 1 AAA 2 AAA 3 AAA 4 AAA 无法加载这样的大查询,当WP_Query的数量变多时,网站返回504错误:

meta_values more than 8-10

如果我过滤的内容少于$args = array( 'showposts' => $per_page, 'post_type' => 'casino', 'no_found_rows' => true, 'update_post_term_cache' => false, 'update_post_meta_cache' => false, 'cache_results' => false, 'tax_query' => array( array( 'taxonomy' => 'casino_categories', 'field' => 'term_id', 'terms' => $term_id ) ), 'meta_key' => 'rating', 'orderby' => 'meta_value_num', 'order' => 'DESC', 'fields' => 'ids', 'meta_query' => array( 'relation' => 'AND', array( 'key' => 'languages', 'value' => 'val1', 'compare' => 'LIKE' ), array( 'key' => 'software', 'value' => 'val1', 'compare' => 'LIKE' ), array( 'key' => 'deposit_methods', 'value' => 'val1', 'compare' => 'LIKE' ), array( 'key' => 'withdrawal_methods', 'value' => 'val1', 'compare' => 'LIKE' ), array( 'key' => 'pending_time', 'value' => 'val1', 'compare' => 'LIKE' ), array( 'key' => 'licenses', 'value' => 'val1', 'compare' => 'LIKE' ), array( 'key' => 'withdrawal_limit', 'value' => 'val1', 'compare' => 'LIKE' ), array( 'key' => 'currenciese', 'value' => 'val1', 'compare' => 'LIKE' ), array( 'key' => 'established', 'value' => 'val1', 'compare' => 'LIKE' ), array( 'key' => 'support', 'value' => 'val1', 'compare' => 'LIKE' ) ) ); $query = new WP_Query( $args ); while ( $query->have_posts() ) { $query->the_post();

,则查询效果很好

管理面板中的所有8 meta_values.都是多个选择字段,因此比较meta_keys无效。

此外,我尝试使用ElasticPress,但是Elastic无法比较"IN"

"LIKE"get_posts()没有帮助。

请帮助我,我正在努力修复一周。

P.S。对不起,英语不好。

1 个答案:

答案 0 :(得分:0)

所以我找到了解决问题的方法!

我创建了一个名为taxonomy的新私人定制filters,并将我的自定义字段移到新税项中。

现在我的WP_Query如下:

$args = array(
  'showposts' => $per_page,
  'post_type' => 'casino',
  'no_found_rows' => true,
  'update_post_term_cache' => false,
  'update_post_meta_cache' => false,
  'cache_results'          => false,
  'tax_query' => array(
    'relation' => 'AND',
    array(
      'taxonomy' => 'casino_categories',
      'field' => 'term_id',
      'terms' => $term_id
    ),
    array( // "Languages" is a parent term for this IDs group
      'taxonomy' => 'filters',
      'field' => 'term_id',
      'terms' => array(20, 19, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42) // Relation "OR"
    ),
    array( // "Software"
      'taxonomy' => 'filters',
      'field' => 'term_id',
      'terms' => array(23, 22)
    ),
    array( // "Filter name"
      'taxonomy' => 'filters',
      'field' => 'term_id',
      'terms' => array(24)
    ),
    // here another 10 terms (filters)
  ),
  'meta_key' => 'rating',
  'orderby' => 'meta_value_num',
  'order' => 'DESC'
);

希望这会对某人有所帮助。