下面是一个如何根据自定义字段值对帖子进行排序的想法,我还提供了一些更改/删除自定义字段值的函数。
<?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;
?>