Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用变量时,in_数组函数不工作?_Php_Wordpress - Fatal编程技术网

Php 使用变量时,in_数组函数不工作?

Php 使用变量时,in_数组函数不工作?,php,wordpress,Php,Wordpress,在下面的代码中,我试图检查$query['skill']值是否包含在$c\u skills中。然而,它不断失败。当我使用我要查找的实际字符串时,例如,“test”,它将按预期运行。我唯一的想法是,$query['skill']可能不会以字符串形式返回,但我无法通过var\u dump来找到答案,因为我正在使用wordpress,并且我正在更改代码以实现ajax查询 global $user_ID; $query = $_REQUEST['query']; if (isset($_REQUEST

在下面的代码中,我试图检查
$query['skill']
值是否包含在
$c\u skills
中。然而,它不断失败。当我使用我要查找的实际字符串时,例如,
“test”
,它将按预期运行。我唯一的想法是,
$query['skill']
可能不会以字符串形式返回,但我无法通过
var\u dump
来找到答案,因为我正在使用wordpress,并且我正在更改代码以实现ajax查询

global $user_ID;
$query = $_REQUEST['query'];

if (isset($_REQUEST['query']['skill'])) {
    if (isset($query['skill']) && $query['skill'] != '') {

global $wp_query, $ae_post_factory, $post, $current_user;
$post_object = $ae_post_factory->get(PROFILE);
$profile_id = get_user_meta( $user_ID, 'user_profile_id', true);
$profile = array('id' => 0, 'ID' => 0);
if($profile_id) {
    $profile_post = get_post( $profile_id );
    if($profile_post && !is_wp_error( $profile_post )){
        $profile = $post_object->convert($profile_post);
    }
}
$current_skills = get_the_terms( $profile, 'skill' );

if (!empty($current_skills)) {
    $c_skills = array();
    foreach ($current_skills as $key => $value) {
                $c_skills[] = $value->name;
            };

    if(in_array( $query['skill'], $c_skills )) {
        $query_args['tax_query'] = array(
                        'skill' => array(
                            'taxonomy' => 'skill',
                            'terms' => 'test',
                            'field' => 'slug'
                        )
                );
    }
}

我认为您的问题来自
$query\u args['tax\u query']

对我来说,关键(技能)与此无关

尽量用简单的语言表达

$query_args['tax_query'] = array(
     array(
            'taxonomy' => 'skill',
            'terms' => 'test',
            'field' => 'slug'
      )
);
如果要查询多个分类法,则在两个数组之间用于skill的位置将用于relation


希望它能在这之后起作用。

你能提供一个
$c_skills
$query['skill']
?$c_skills=>[“test”,“test2”]和$query['skill']的变量转储吗?$c_skills=$\u请求['query']Hi@Benoti我想你误解了。我需要验证$query['skill'],它保存了wordpress上表单中的查询字符串,在我将其用于tax_查询之前,我需要验证它是否存在于特定数组中。很抱歉让你感到困惑,再看一次你的代码,我不知道这是否会成为一个问题:在foreach结束奖之后,你有一个分号。