字preSS查询返回每一邮政局 [英] WordPress Query Returning Every Post

查看:157
本文介绍了字preSS查询返回每一邮政局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义WP查询,以搜索一个自定义字段,使用数组。

I have a custom WP query that searches a single custom field, using an array.

自定义字段是一个职位的原产国。我使用的阵列是各个国家中的区域的名称。我们的目标是能够返回从一个地区或大陆的所有帖子。

The custom field is for the country of origin of a post. The array I'm using are the names of the various countries in a region. The objective is to be able to return all posts from a region or continent.

下面是我的查询:

$args = array(
        'posts_per_page' => '-1',
        'cat' => '4',
        'meta_query' => array(
                array(
                'meta_key' => 'Country',
                'meta_value' => $country_search,
                'compare' => 'IN'
                )
        )
    );
    $country_query = new WP_Query( $args );

$ country_search 变量是内爆数组:阿尔巴尼亚,安道尔,亚美尼亚,奥地利,白俄罗斯,比利时等

The $country_search variable is an imploded array: 'Albania','Andorra','Armenia','Austria','Belarus','Belgium', etc.

什么情况是,无论我搜索哪个地区,而返回正确的国阵,查询将返回所有的帖子在数据库中。

What happens is that no matter which region I search for, while the correct country array is returned, the query returns all of the posts in the database.

我敢肯定,这是简单的东西,但我的头疮撞它靠在键盘。

I'm sure it's something simple, but my head is sore from banging it against the keyboard.

我极大的AP preciate任何帮助。

I greatly appreciate any help.

TY

推荐答案

感谢所有的帮助!

据捕获的原始图像证明是问题的组合:

It tured out to be a combination of issues:


  1. 而不是内爆的 $ country_search_array ,它需要
    加入作为对查询。

  2. 因为它是一个数组,我们不能使用=的比较值。它需要IN

  1. Instead of imploding the $country_search_array, it needs to be added as is to the query.
  2. Since it's an array, we can't use the '=' for the compare value. It needs to be 'IN'

我不能想通了没有,我收到这里的援助。再次,感谢!

I couldn't have figured it out without the assistance I received here. Again, thanks!

这篇关于字preSS查询返回每一邮政局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆