Skip Navigation

[Resolved] Show Posts with empty Custom Filed

This support ticket is created 5 years ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 1 reply, has 2 voices.

Last updated by Minesh 5 years ago.

Assisted by: Minesh.

Author
Posts
#1445455

Hi!
How can i show my posts in view tables that does not contain data for any custom filed of it.
For example i want to show all posts that dose not have agency title in it.
Agency title is custom filed of posts.

Must let me know
Regards.

#1445677

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

The easiest way is to use the Views filter hook: wpv_filter_query

Please try to add the following code to your current theme's functions.php file.
OR
You can add it to the "Custom Code" section offered by Toolset:
=> https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/

add_filter( 'wpv_filter_query', 'func_custom_field_not_exists_posts', 10, 3 );
function func_custom_field_not_exists_posts( $query_args, $view_settings, $view_id ) {
    if($view_id = 999999) {
        $query_args['meta_query'][] = array(
            'key'     => 'wpcf-field-slug',
            'compare' => 'NOT EXISTS',
        );
    }
    return $query_args;
}

Where:
- Replace 999999 with your original view ID
- Repalce "field-slug" with your original field slug.

More info:
=> https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query