How to update custom field of a posts in a particular category

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 … Read more

use custom field value as post category in loop

Nevermind. Got it working with: <?php global $wp_query; $paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1; $store_name = (get_post_meta($post->ID, ‘store_name’, true)); query_posts(array(‘posts_per_page’ => ’10’,’paged’=>$paged,’category_name’=>$store_name)); ?>

Custom fields won’t update

‘name’ is what gets saved as key in the post meta data, so do a str_replace for the category name, before saving: // Wrong: name=”My Category” echo ‘<input type=”checkbox”‘ . $i . ‘name=”.””‘.$category->name.'”‘.’value=”” />’.$category->name; // Right: name=”my_category” $name = str_replace( ‘ ‘, ‘_’, strtolower( $category->name ) ); $checked = get_post_meta( …etc… ); echo “<input type=”checkbox”{$i} … Read more

Displaying custom field meta within WP_query loop

Your query should work if you call global $post and don’t reset the query (not needed when using WP_Query). You can also try using tax_query. $tax = ‘issue’; $terms = get_terms( $tax ); foreach ( $terms as $term ) : echo $term->name; $args = array( ‘post_type’ => $post_type, ‘post_per_page’ => -1, ‘post_status’ => ‘publish’, ‘caller_get_posts’ … Read more

Get custom post fields from multiple metaboxes

If I understand your question correctly, you would like to get all metadata for “products” across all posts. In other words, multiple posts have metadata with key “products” and you want to get those values. If this is correct, you should use get_post_custom_values, which is well documented in the codex: http://codex.wordpress.org/Function_Reference/get_post_custom_values. As a side note, … Read more

wp_get_attachment_image_src() with advanced custom fields returning empty

What’s in get_sub_field(‘image’)? wp_get_attachment_image_src() parameter 1 should be the attachment id, not the attachment src, if that’s what you have. I use the following function to get an attachment ID from an image url as as far as I know WP doesn’t have a method for this at present. function get_attachment_id_from_src ($src) { global $wpdb; … Read more