Move from old custom field to new post_thumbnails

Had the same issue last week and here is what i did: if (has_post_thumbnail()) //if the post already has a post thumbnail then just use that the_post_thumbnail($size=”post-thumbnail”, $attr=””); else{ //if not then convert the custom field to the post thumbnail and display that $at_url = get_post_meta($post->ID, ‘image’, true); $at_id = get_image_id_by_url($at_url); delete_post_meta($post->ID, ‘image’); if ($at_id){ … Read more

Change wp_get_attachment_image attributes (src and srcset) on specific custom field

You won’t be really able to tell which context the image is being used in in the wp_get_attachment_image_attributes filter, but you can pass custom attributes to wp_get_attachment_image() in the template directly with the 4th argument. Then you can use wp_get_attachment_image_url() and wp_get_attachment_image_srcset() to get the values for those attributes: $image = get_field(‘image’); $size=”gallery”; echo wp_get_attachment_image( … Read more

Automatically fill custom field value on post publish/update

See add_meta_box which has a lot of demo code for working with meta fields. Here is the most relevant part for you: /* Do something with the data entered */ add_action( ‘save_post’, ‘myplugin_save_postdata’ ); /* When the post is saved, saves our custom data */ function myplugin_save_postdata( $post_id ) { // First we need to … Read more

How to get users by a custom field / by user meta data?

What is the exact meta_key and meta_value for the field I created using the function custom_user_profile_fields ? created_by and some user ID, for example: $args = array( ‘meta_key’ => ‘created_by’, ‘meta_value’ => 123, ) You could use a meta_query for more complex searches. $args = array( ‘meta_query’ => array( array( ‘key’ => ‘created_by’, ‘compare’ => … Read more

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