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

Data URI in custom fields

Hook on ‘save_post’, and after normal saving metabox routine create the data uri using php functions base64_encode and file_get_contents. With a bit of logic skip saving if not necessary (data uri already_saved). In next example I assume the post thumbnail url is setted in a metabox, and the name of the field is ‘post_thumbnail’. See … Read more

HM CMB: Role Select

There is a list of roles in the $wp_roles WordPress global object. Set $wp_roles to a global at the top of your method of function: global $wp_roles; Use a Select Field to populate the options: array( ‘id’ => $prefix . ‘role’, ‘name’ => ‘Role’, ‘type’ => ‘select’, ‘use_ajax’ => false, ‘options’ => $wp_roles->get_names(), ), Note: … Read more

SQL / wp_update_post: change post custom field to CPT post taxonomy

You’ve got the right idea but you are using some of the functions and function arguments incorrectly. // get all post IDs $post_ids = get_posts( array( ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’, ‘numberposts’ => -1, // get all posts. ‘fields’ => ‘ids’, // Only get post IDs ) ); // info: custom field ‘actor’ = … Read more