WordPress Posts abfragen, bei denen ein Custom Field null ist

Folgender Code ermöglicht dir, Posts (oder Custom Post Types) abzufragen, bei denen ein Custom Field null ist:

$args = [
    'posts_per_page' => -1,
    'post_type' => 'my_post_type', // ändern
    'post_status' => 'publish',
    'order' => 'DESC',
    'orderby' => 'date',
    'meta_query' => [
        'relation' => 'OR',
        [
            'key' => 'my_custom_field', // ändern
            'compare' => 'NOT EXISTS'
        ]
    ]
];

// Query bauen
$query = new WP_Query($args);

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert