I need query help!
I am trying to set up a
get_comments) for keys that aren't yet set.
I have some code that allows moderators to add a custom meta key to individual comments. Click the checkbox and the meta key is set to
shadow, unclick it the meta key is set to an empty string.
This means that there are three possible states for a comment to have. It can either have the 'shadow' meta key, it can have an empty string and the meta key, or the meta key could not be set.
What I would like to do is query all comments that either don't have this meta key set or have the meta key that is NOT shadow. It is fairly easy to select all comments that have the meta key not equal
shadow but I haven't found a away to also select comments that don't have the meta key set.
This is the code I am using, but it doesn't work. It selects every comment that has the meta key set, regardless of what it is set to.
$comments = get_comments( array( 'meta_query' => array( 'relation' => 'OR', array( // Select comments that don't have the 'shadow' p3_comment_status meta 'key' => 'p3_comment_status', 'value' => 'shadow', 'compare' => '!=' ), array( // Select comments that don't have the p3_comment_status set 'key' => 'p3_comment_status', 'compare' => 'NOT EXISTS' ) ) ) );
[Moderator Note: Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum's parser.]
Any help would be appricieated.