Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm developing a system where user can buy scratch card number using pre-paid balance. I already created balance system using user meta. Now I need to delivery card number to users upon payment. As payment system is ready, I need an idea which will help me to deliver card number. Card numbers will be stored in database. I'll deliver them. Custom post type can be used probably but couldn't recognize how I deliver them.

For instance, User want buy a card of $10. I already stored 5 cards of $10, 3 cards of $20. If user make payment, system will deliver the card number which wasn't previously sold.

I need idea. Please suggest me.

Update: I got an idea. I'll create a custom post type called 'Card' with three meta key fields called 'Amount', 'Number' and 'Status'. When a specific function will run, a query will be run for searching the post type for certain amount and where Status will be "Unused". Then an email will be sent to the user with the card number and custom field 'Status' will be updated to "Used". Now I need an idea to search the post. I appreciate your help.

share|improve this question

2 Answers 2

up vote 2 down vote accepted

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;
?>
share|improve this answer
    
Thanks. You missed $the_query = new WP_Query($args); –  Enthusiast Aug 2 '12 at 4:08
    
oops, updated answer, thanks for pointing out. –  amit Aug 2 '12 at 7:26
    
:) Your answer really helped me to figured out the way to work. Thanks again. –  Enthusiast Aug 2 '12 at 7:58
    
I'm glad I was able to help –  amit Aug 2 '12 at 8:00

Too easy, follow Amit's suggestion with

$args = array(
    'post_type' => 'card', // custom post type name - card
    'posts_per_page=1',
    '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 ) 
        )
    )
);
share|improve this answer
    
Yes, I did that with 'posts_per_page' => 1, –  Enthusiast Aug 2 '12 at 4:24

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.