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 have a function that performs some custom queries to get specific information regarding a post (children count, dates, etc).

I am wondering if it is possible to send this custom query info (set as a variable) to a custom field automatically when I update the page.

share|improve this question

1 Answer 1

up vote 0 down vote accepted

Sure. Hook into the save_post action, then perform your custom queries upon save, and store them as custom fields of the post.

add_action('save_post', 'my_extra_meta_saver');
function my_extra_meta_saver($post_id)
{
    global $post;

    // Prepare whatever extra information you want here

    // Save each piece of info in a custom field
    update_post_meta($post_id, 'meta_key', 'meta_value');
}
share|improve this answer
    
Does the add_action have to go in a plugin or can it be placed in the functions file as well, outside of the function? –  AlxVallejo Nov 21 '11 at 20:02
    
It can go in functions.php. –  Geert Nov 21 '11 at 20:49

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.