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 lot of posts under category 'tution', which has custom field called 'video'. i need to update the 'video' value with same youtubeurl i.e all post would have the same value in the custom field 'video'. how should i proceed. Is their a query?

share|improve this question

1 Answer 1

Use get_posts to get all the posts in this category, then loop over it and update the post meta for every post.

<?php
//get_posts uses same parameters as WP_Query hence using 'category_name'
$tut_posts = get_posts(array('category_name'=>'tution', 'post_status'=>'publish'));
$url = //some youtube video url here
if(!empty($tut_posts)){
    foreach($tut_posts as $tut_post){
        update_post_meta($tut_post->ID, 'video', $url);
    }
}

Please check if this works for you.

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.