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

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)

The best way to collision check in WP

I don’t think there is a built in mechanism for searching the meta table for a key/value pair other than a full blown post search with WP_Query. I’d consider that overkill. Just query the table: $unique = $wpdb->get_var( “SELECT meta_id FROM {$wpdb->postmeta} WHERE meta_key = ‘unique_code’ AND meta_value=”{$random}” LIMIT 1″ ); I can’t help but … Read more

How do I convert all custom_field php timestamps in the database to js timestamps?

ACF using milliseconds is not standard for timestamps, and nor is it useful. How much accuracy do you need? Bear in mind that converting to something like yyyymmdd will not accommodate timezones. If you have access to PHPMyAdmin (or similar) and know your way around SQL, running a quick query would probably be the easiest … Read more