custom field - WP meta_query args not working in function

I have three query args for filtering posts in grid. By Author and Status works fine, but ACF meta_query not work. I se

I have three query args for filtering posts in grid. By Author and Status works fine, but ACF meta_query not work. I setup field as select:

I need when is selected "Ne" value hide post from grid, but it still display there.

    function my_super_filer_function2($query_args){
    global $post;

    $post_author = $post->post_author;
    $query_args['author'] = $post_author;
     $query_args['post_status'] = array('publish', 'future');

    $query_args ['meta_query']= array(
'meta_key' => 'zobrazitnatridy',
'meta_value' => 'Ne',
'meta_compare' => '!='
);
    return $query_args;
}
add_filter('my_super_filter2', 'my_super_filer_function2');

What is wrong there?

I have three query args for filtering posts in grid. By Author and Status works fine, but ACF meta_query not work. I setup field as select: http://prntscr/pi6m66

I need when is selected "Ne" value hide post from grid, but it still display there.

    function my_super_filer_function2($query_args){
    global $post;

    $post_author = $post->post_author;
    $query_args['author'] = $post_author;
     $query_args['post_status'] = array('publish', 'future');

    $query_args ['meta_query']= array(
'meta_key' => 'zobrazitnatridy',
'meta_value' => 'Ne',
'meta_compare' => '!='
);
    return $query_args;
}
add_filter('my_super_filter2', 'my_super_filer_function2');

What is wrong there?

Share Improve this question edited Oct 12, 2019 at 1:39 heroj asked Oct 12, 2019 at 1:32 herojheroj 238 bronze badges 0
Add a comment  | 

1 Answer 1

Reset to default 0

You're very close to it just need to to modify your code little bit. See I've update code for you.

function my_super_filer_function2($query_args){
    global $post;
    $post_author = $post->post_author;
    $query_args['author'] = $post_author;
    $query_args['post_status'] = array('publish', 'future');
    $query_args['meta_query'] = array(
        array(
            'key' => 'zobrazitnatridy',
            'value' => 'Ne',
            'compare' => '!='
        )
    );
    return $query_args;
}
add_filter('my_super_filter2', 'my_super_filer_function2');

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745087921a4610517.html

相关推荐

  • custom field - WP meta_query args not working in function

    I have three query args for filtering posts in grid. By Author and Status works fine, but ACF meta_query not work. I se

    11小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信