Here is an idea how we can sort the post based on custom field value and also I’d given some functions to change/delete custom field values.
<?php
$args = array(
'post_type' => 'card', // custom post type name - card
'meta_query' => array(
'relation' => 'AND', // return post with meta-field key status = ununsed & amount = 10
array(
'key' => 'status',
'value' => 'unused',
),
array(
'key' => 'amount',
'value' => 10 // Array usage to show mulitple values- 'value' => array( 10, 20 )
)
)
);
$the_query = new WP_Query($args);
//this will show list of all available cards
while ( $the_query->have_posts() ) : $the_query->the_post();
if(/* condition paid */) {
$number = get_post_meta($post->ID, 'number', true);
echo $number; // or send email then
//change status from unused to used
update_post_meta($post_id, number, used, $number);
//delete amount custom field
delete_post_meta($post_id, amount, 10);
} else {
//do stuff if not paid
}
endwhile;
?>