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 trying to use the count of the amount of people that register a post id to a table in the DB. I want to save this COUNT value to the post_meta so when I display the list of posts it can also show the amount of people "registered".

function get_custom_field($field_name){
    return get_post_meta(get_the_ID(),$field_name,'true');

$attendee_number = $wpdb->get_var("SELECT COUNT(user_id) FROM ".$wpdb->prefix."mro_attendees WHERE event_id = ".$project_id);
$attendee_limit = get_custom_field('project_limit');
$attendee_status = $attendee_number . '/' . $attendee_limit;

I then take the value of attendee_status and use it in a hidden field which saves to the post meta and then call it as one of the values in a loop I create.

The issue is that it does not update this value if I change the limit on the page, it can not dynamically change in other words. It saves it as is when it loads on the post edit page. So when I load the page to create the post, there is no COUNT so its 0 entries and there is no limit so it's NULL. So the attendee_status variable will be 0/

How do I create this X/Y limit status so that it updates when there is a new entry or when the limit custom field is updated?

share|improve this question
    
get_custom_field() is no WordPress core function. Support for 3rd plugins is off topic. Also you are talking in riddles. I can't figure out what your setup really is and what happens. If you want, you can file an edit, rephrase the description and make it more clear. –  kaiser Jun 23 at 16:41
    
It's not a plugin, I just added that function to easily get custom field data. –  Alex Howell Jun 23 at 16:48
    
I don't understand the question. –  Joey Yax Jun 23 at 17:43
    
I want to have a project limit status that is tied to each post id. But I don't know how to save them to the post id individual. It has the amount of people currently attending and the limit combined into one variable but I don't know how to create that value and tie it to each post id on the front end. I want it hidden on the front end and saved to the post meta so it can be retrieved. I can't do it from the edit menu because it will save the status without it being dynamic. It can't change from the admin edit pot page. So I can't save or set the value there. –  Alex Howell Jun 23 at 17:55
    
Not as comment. As edit to your question please. –  kaiser Jun 24 at 5:47

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.