Get meta field value of all catgories

If you’d use the get_categories() function to get all the categories, you can then loop through them. Partial pseudo code, but this will do the trick: $categories = get_categories( array() ); $colors = array(); foreach ( $categories as $category ) { $cat_meta = get_option( ‘meta_field_’ . $category->slug ); if (isset($cat_meta[‘color’])){ $colors[ $category->term_id ] = $cat_meta[‘color’]; … Read more

SQL: Select wordpress posts with given text string and add a custom field to them?

Here you go (you’re really close): INSERT INTO wp_postmeta (post_id, meta_key, meta_value) SELECT ID AS post_id, ‘customer_reviews’ AS meta_key, ‘On_or_delete’ AS meta_value FROM wp_posts WHERE wp_posts.post_content LIKE ‘%Customer Reviews%’ AND wp_posts.post_type=”post”; ` Edit: You could also just change IS IN to IN. I rewrote the from part of the query since a subquery was unnecessary … Read more

How to hide post meta

OK, just don’t use the_meta function and display these fields with your custom code. You can use something like this: function my_filtered_meta($disabled_metas =array()) { if ( $keys = get_post_custom_keys() ) { echo “<ul class=”post-meta”>\n”; foreach ( (array) $keys as $key ) { $keyt = trim($key); if ( is_protected_meta( $keyt, ‘post’ ) || in_array($keyt, $disabled_metas ) … Read more

Displaying an ACF list of users

You can use get_author_posts_url() or get_the_author_meta(): $values = get_field( ‘editor’ ); if ( $values ) { $editors = array(); foreach ( $values as $value ) { $link = get_author_posts_url( $value[‘ID’] ); //get the url $nicename = $value[‘user_nicename’]; $editors[] = sprintf( ‘<a href=”https://wordpress.stackexchange.com/questions/106854/%s”>%s</a>’, $link, $nicename ); //create a link for each author } echo ‘Edited by: … Read more

Filter unique custom field value based on custom taxonomy category or other custom field

The filtering can be done with this function totally untested function filter_custom_fields($key=”, $terms=””, $tax=”, $selkey=”, $selval=””) { global $wpdb; $include=””; if ( $selkey && $selval && ( is_string($selval) || is_array($selval) ) ) { $include = ” AND post_id IN (” . $wpdb->prepare(“SELECT DISTINCT post_id FROM $wpdb->postmeta WHERE meta_key = %s AND meta_value “, $selkey ); … Read more

Custom field image to Featured Image

I put this together for you as a proof-of-concept. This class will migrate both attachment IDs and external image URLs into your featured images. class Featured_Image_Migration{ #Instantiate the migration by hitting /wp-admin/?migrate-post-meta=foobar protected $key = ‘migrate-post-meta’; protected $secret=”foobar”; #This is your legacy meta_key protected $meta_key = ‘mainimg_medium’; function __construct(){ #Force this to run last so … Read more

Custom meta boxes in RSS feed

Try, not tested, add_filter(‘the_content_feed’,’add_my_fields_to_rss’); function add_my_fields_to_rss($content) { global $post; $mymeta = get_post_meta($post->ID, ‘my_meta’, true); $content .= $mymeta; return $content; }

Add specific custom fields to post formats

your options are this: http://wordpress.org/plugins/advanced-custom-fields/ and this http://wordpress.org/plugins/types/ Both will allow you to add different custom fields depending on which custom post type you like the field to appear.. (Though I prefer the first one because it is more flexible for me)

Update custom field value

Something like this should do: function track_editor_wpse_108606() { if (is_single()) { $current_user = wp_get_current_user(); if (user_can( $current_user, ‘editor’ )) { global $post; $current = get_post_meta($post->ID,’editor_tracker’,true); $current = (!empty($current)) ? $current + 1 : 1; update_post_meta($post->ID,’editor_tracker’,$current); } } } add_action(‘wp_head’,’track_editor_wpse_108606′); This is not especially efficient. You are reading and writing to the database for these page … Read more