I'm trying to make a wp query to WP Post Meta Table where I want to check the post's META KEY and its META VALUE if its EMPTY or NOT.
The meta key is wc_pay_per_post_product_ids.
IF the statement is TRUE, display the following:
<h1>The Meta Key Is Empty or NULL</h1>
<div class="row"><div class="col-2">One</div><div class="col-10">Two</div></div>
ELSE:
<h1>The Meta Key Is NOT Empty or NULL</h1>
<div class="row"><div class="col-4"></div><div class="col-4"></div><div class="col-4"></div></div>
Here's the complete code.
<?php
global $wpdb;
$post_id = get_the_ID();
$meta_value = 'wc_pay_per_post_product_ids';
$args = array(
'post_type' => 'post',
'meta_query' => array(
array(
'post_id' => get_the_ID(),
'key' => 'wc_pay_per_post_product_ids',
'compare' => 'EXIST' // CHECK THE VALUE OF META KEY IF EXISTS?
)
)
);
if ($arg == TRUE) {
echo '<h1>The Meta Key Is Empty or NULL</h1><div class="row"><div class="col-2"></div><div class="col-10"></div></div>';
} else {
echo '<h1>The Meta Key Is NOT Empty or NULL</h1><div class="row"><div class="col-4">ONE</div><div class="col-4">TWO</div><div class="col-4">THREE</div></div>';
}
?>
Here's the screenshot of my table:
The issue I'm encountering is it always return the result "The Meta Key Is NOT Empty or NULL" Any idea what's wrong?