Saving attachment custom fields

Got it: add_filter(“attachment_fields_to_edit”, “my_image_attachment_fields_to_edit”, null, 2); function my_image_attachment_fields_to_edit($form_fields, $post) { $form_fields[“OwnersHeading”][“tr”] = ” <tr> <td colspan=’2′ style=”font-size:16px;padding-left:15px”>Tag Users:</td> </tr>”; // get list of users $wp_user_query = new WP_User_Query( array( ‘orderby’ => ‘display_name’ ) ); $authors = $wp_user_query->get_results(); if (!empty($authors)) { foreach ($authors as $author) { $belongs_to_value = (bool)get_post_meta( $post->ID, “_owner_$author->ID”, true ); // create the … Read more

Post edit – Media Library – Only get images from current post

This will lock uploads to “Uploaded to this post” and will not show “All media items” or other options in WordPress media panels. Add this code to your function.php file add_action( ‘admin_footer-post-new.php’, ‘firmasite_mediapanel_lock_uploaded’ ); add_action( ‘admin_footer-post.php’, ‘firmasite_mediapanel_lock_uploaded’ ); function firmasite_mediapanel_lock_uploaded() { ?> <script type=”text/javascript”> jQuery(document).on(“DOMNodeInserted”, function(){ // Lock uploads to “Uploaded to this post” jQuery(‘select.attachment-filters … Read more

Automatically add image caption with values from a post parent field?

In the filter, you will need to find the post parent of $post, get the value of the custom field of parent post and then add that value to $post[‘post_excerpt’] (where the caption is stored): add_filter(‘attachment_fields_to_save’, ‘wpse_insert_custom_caption’, 10, 2); function insert_custom_default_caption($post, $attachment) { //Check if the $post is attached to a parent post if( $post->post_parent … Read more

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