0

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?

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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