Get an image from the media library. Struggling with the code?

If you want to exit the loop after you find an attachment, use break. // Define $programme and pull up $attachments as above $attachment_url=””; foreach ( $attachments as $attachment ) { if ($attachment->post_title == $programme) { $attachment_url = wp_get_attachment_url($attachment->ID); break; } } if ( $attachment_url ) { echo $attachment_url; } else { echo ‘/images/nontvimg.jpg’; }

How to add media from front-end to an existing post and edit file title

First add to your for the new input field: <form id=”file-form” enctype=”multipart/form-data” action=”<?php echo $_SERVER[‘REQUEST_URI’]; ?>” method=”POST”> <p id=”async-upload-wrap”> <label for=”async-upload”>upload</label> <input type=”file” id=”async-upload” name=”async-upload”> <input type=”submit” value=”Upload” name=”html-upload”> </p> <p id=”image_title”> <label for=”image_title”>Image Title</label> <input type=”text” id=”image_title” name=”image_title” value=””> </p> <p> <input type=”hidden” name=”post_id” id=”post_id” value=”<?php echo $post_id ?>” /> <?php wp_nonce_field(‘client-file-upload’); ?> <input … Read more

How to list “invisible” Auto Drafts?

try pasting this in your theme’s functions.php file add_filter( ‘parse_query’, ‘display_autosave_and_revisions’ ); function display_autosave_and_revisions( $query ) { global $pagenow,$typenow; if ( is_admin() && $pagenow == ‘edit.php’ && $typenow == “post”) { $query->query_vars[‘post_type’] = array(‘revision’,’post’); $query->query_vars[‘post_status’] = ‘any’; } }

How can I rewrite old attachment URLs?

Figured it out! The function I needed to hook is called “the_content”, because that’s the post content that is pulled directly from the database. I added this code into the functions.php file for my theme. function force_https_the_content($content) { if ( is_ssl() ) { $content = str_replace( ‘src=”http://’, ‘src=”https://’, $content ); } return $content; } add_filter(‘the_content’, … Read more

i want attachment.php to return the image

Answer is this (thanks to WordPress Vampire here : Change Attachment Post URLs to File URLs) : Create an attachment template file within the theme. Since we are only interested in images, the file should be image.php <?php if ( have_posts() ) { the_post(); $image_url = wp_get_attachment_url(); } header(‘Location: ‘.$image_url); ?>

changing the default picture size link url

You can use: <?php $image_attributes = wp_get_attachment_image_src( $attachment_id, array(1024,1024) ); ?> <a href=”https://wordpress.stackexchange.com/questions/37124/<?php echo $image_attributes[0]; ?>”>xxx</a> See http://codex.wordpress.org/Function_Reference/wp_get_attachment_image_src If the picture is too small the original will show, otherwise cropped version (1024×1024). Update: Didn’t understand your question correct. Here is what you need: First of all add a thumbnail size for your custom max size … Read more

Getting attachment post using wp_get_attachment_link

Yes, if you pass third ($permalink) parameter as true in wp_get_attachment_link() image will link to attachment’s page not image itself. You can use wp_get_attachment_link filter to change behavior of that parameter, but in this case it simply means overwriting whole function. Instead I would use wp_get_attachment_image() and get_permalink() UPDATE Maybe wp_get_attachment_image() would fit in this … Read more

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