So in my below code I am trying to check whether the $query[‘skill’] value is contained in $c_skills. However it keeps failing. When I use the actual string that I am looking for eg “test” then it functions as intended. My only thought is perhaps $query[‘skill’] doesn’t return as a string? But I cant do a var_dump to find out since I am using wordpress and I am changing code to effect ajax query.

    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'


Read more here: in_array function not working when using variable?


If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Wordpress related questions and answers: