Sauter la navigation

[Résolu] In a view, show only posts that DONT have a date field set.

Ce fil est résolu. Voici une description du problème et la solution proposée.

Problem:
In a view, show only posts that DONT have a date field set.

Solution:
You need to use view's filter "wpv_filterP_query" to display only posts where custom field is not set.

You can find the proposed solution, in this case, with the following reply:
https://toolset.com/forums/topic/in-a-view-show-only-posts-that-dont-have-a-date-field-set/#post-1168656

Relevant Documentation:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

This support ticket is created Il y a 6 années et 1 mois. 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)

Marqué : ,

Ce sujet contient 2 réponses, a 2 voix.

Dernière mise à jour par davidS-53 Il y a 6 années.

Assisté par: Minesh.

Auteur
Publications
#1168422

I am trying to: show all posts that DONT have a value set for custom field expiry-date.

I can show all posts that DO have this field set by using "Select items with field: Expiry Date is a string different from" (as in different from blank)

However, the opposite "Select items with field:Expiry Date is a string equal to" (as in equal to blank) doesn't work. Perhaps I;m missing something here?

#1168656

Minesh
Supporter

Les langues: Anglais (English )

Fuseau horaire: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - here you need to make sure that does meta_key exists for the posts where the custom date field expiry-date is NOT set in the database table postmeta. If No:

You need to use view's filter: wpv_filterP_query

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

Where:
- Replace 999999 with your original view ID

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

If solution shared above is the actual case and works for you. We encourage you to file a feature request here for this case with the following link:
=> https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/

#1177950

Thanks- however I had to use

if($view_settings['view_id'] == 9999){

Instead of

if($view_id = 9999) {

Your code applied the filter to every view for some reason.