How can I display a link to a post’s (Word doc or pdf) attachment?

Try this: <?php if ( $attachments = get_children( array( ‘post_type’ => ‘attachment’, ‘post_mime_type’ => array(‘application/doc’,’application/pdf’), ‘numberposts’ => 1, ‘post_status’ => null, ‘post_parent’ => $post->ID ))); foreach ($attachments as $attachment) { echo ‘<a href=”‘ . wp_get_attachment_url( $attachment->ID ) . ‘”>Download Spec Sheet</a>’; echo ‘</div>’; } ?>

Echo Permalink in Attachment outside of loop?

Jez, unpatient Jez 🙂 <?php $args = array( ‘post_type’ => ‘attachment’, ‘numberposts’ => -1, ‘post_status’ => null, ‘post_parent’ => $post->ID ); $attachments = get_posts( $args ); if ( $attachments ) { foreach ( $attachments as $attachment ) { echo ‘<li> <a href=”‘. get_permalink($attachment->ID) .'” title=”Permanent Link to<?php the_title_attribute(); ?>”>’; echo wp_get_attachment_image( $attachment->ID, ‘full’ ); echo … Read more

Post Gallery list attachments except the one used as post thumbnail

You can use the exclude parameter. global $post; $args = array( ‘exclude’ => get_post_thumbnail_id( $post->ID ) ‘post_type’ => ‘attachment’, ‘post_mime_type’ => ‘image’, ‘numberposts’ => -1, ‘orderby’ => ‘menu_order’, ‘order’ => ‘ASC’, ‘post_parent’ => $post->ID ); $images = get_posts($args); http://codex.wordpress.org/Template_Tags/get_posts http://codex.wordpress.org/Function_Reference/get_post_thumbnail_id

Correct attachment size

You need to echo your wp_get_attachment_image, BUT since this function returns a HTML object in the form of, <img src=”https://wordpress.stackexchange.com/questions/67508/path/to/image.jpg”/> It’s not going to work because you are are trying to return this function withing the href attribute of an anchor <a> This is wrong, <a href=”https://wordpress.stackexchange.com/questions/67508/<?= wp_get_attachment_image( $attachment->ID,”blog-thumb’); ?>”></a> This is right, <a href=”https://wordpress.stackexchange.com/questions/67508/<?php … Read more

Add audio attachment link to RSS

You can add this part into your function: $audios =& get_children(‘post_type=attachment&post_parent=”.$post->ID.”&post_mime_type=audio’ ); foreach ( $audios as $id => $audio ){ $content.='<a href=”‘.wp_get_attachment_url($id).'” target=”_blank”>’.$audio->post_title.'</a> ‘; } to add audio links into your feed content. I’m using get_children() here, you can read more about it here: http://codex.wordpress.org/Function_Reference/get_children Edit: Here is the whole function: function featuredtoRSS($content) { global … Read more

Weird string offset errors when displaying post attachments

Since you’ve used the true argument for get_post_meta, $blogimages will be a single array, not a multidimensional one. So instead of $blogimages[0][‘blog-image-inside’], just use $blogimages[‘blog-image-inside’]. For absolute sanity, you might also want to check $blogimages before you use it: ‘exclude’ => [ $thumb_ID, isset( $blogimages[‘blog-image-inside’] ) ? $blogimages[‘blog-image-inside’] : 0, isset( $blogimages[‘blog-image-front’] ) ? $blogimages[‘blog-image-front’] … Read more

Attach pdf from dynamic url

You can try to do it in two ways. The first one, much more simple, is to save a temporary PDF file somewhere, for example in a uploads directory, use it as attachment and delete if after the call to wp_mail() function is made: function my_custom_save_post( $post_id, $post, $update ) { if( ! $update ) … Read more

how to get random media id from media gallery

You can use get_posts() function to get random post, without additional php manipulation. Just change default orderby attribute to “rand” and set number of posts attribute equals to “1”. $image = get_posts( array( ‘orderby’ => ‘rand’, //random order ‘numberposts’ => 1, // numberposts, not posts_per_page ‘post_type’ => ‘attachment’, ‘post_mime_type’ => ‘image’, ‘post_status’ => ‘inherit’ ) … Read more

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