Save custom user meta on registration

You have to trigger the following hooks: user_register personal_options_update edit_user_profile_update add_action(‘user_register’, ‘addMyCustomMeta’); add_action(‘personal_options_update’, ‘addMyCustomMeta’ ); add_action(‘edit_user_profile_update’,’addMyCustomMeta’ ); function addMyCustomMeta( $user_id ) { update_user_meta( $user_id, ‘user_phone’, $_POST[‘user_phone’] ); } Hope that helps!!

Advanced Custom Fields Validation

There is now, I just posted a plugin that I wrote to do validation for Advanced Custom Fields to the WordPress repository. It lets you do server side validation using either PHP code or regex, jQuery masked inputs, as well as unique value settings. http://wordpress.org/extend/plugins/validated-field-for-acf/

How to position a custom field before the editor

This can be solved using this nice snippet and edit_form_after_title hook. But I haven’t tested what happens when more than one meta box exists. With a single ACF field (position:normal, style:no-metabox) it works: add_action( ‘edit_form_after_title’, ‘pre_title_metabox_wpse_94530’ ); function pre_title_metabox_wpse_94530() { global $post, $wp_meta_boxes; do_meta_boxes( get_current_screen(), ‘normal’, $post ); unset( $wp_meta_boxes[‘post’][‘normal’] ); } And if it … Read more

Add custom fields when specific templates are selected

Can you do that? Absolutely! You simply need to query the _wp_page_template meta key value of the $post object, and act accordingly. Perhaps something like so: // Globalize $post global $post; // Get the page template post meta $page_template = get_post_meta( $post->ID, ‘_wp_page_template’, true ); // If the current page uses our specific // template, … Read more

Using get_posts with arguments found in meta keys

get_posts accepts any of the arguments that WP_Query accepts. So there’s a few options. 1. meta_key and meta_value <?php get_posts(array( // some more args here ‘meta_key’ => ‘some_key’, ‘meta_value’ => ‘some value’ )); 2. meta_query meta_query is more sophisticated that using meta_key and meta_value. For instance, say you wanted to get posts that have the … Read more

Change behavior of “Insert into Post” based on attachment metadata

In case it’s helpful to anyone else, here’s what my code looked like to achieve this. I didn’t end up saving the attachment data at all, per tbuteler’s suggestion, but rather than using $_REQUEST I found I could use the $attachment array directly: function my_attachment_fields_to_edit( $form_fields, $post ) { $supported_exts = supported_types(); // array of … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)