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.

As per this thread I'm scheduling a wp_cron every hour which runs a function. The function I'm running is reasonably lengthy and I didn't want authors to have to deal with the waiting times.

My question is this - when creating a function which runs from the following code ($ids is a list of post IDs):

$ids = unserialize( get_option( 'my_updated_posts' ) );
foreach( $ids as $v ) {
    YOUR_FUNCTION_HERE( $v );
}

How do I a) retrieve content if the id relates to a Post type and then update it, or b) update meta fields if said id is actually a species Custom Post Type?

For b), will I have to update each meta field individually or is there a filter I can apply?

Thanks in advance,

share|improve this question

1 Answer 1

up vote 1 down vote accepted

I would filter which posts go into the option, that's light enough processing that it can be done on that end.

To get the content of the post you can use get_post( $v );.

To get the metavalues for the post you can use get_post_custom( $v );.

To update the meta values you will use update_post_meta(). You will have to do these individually.

share|improve this answer

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.