I think I’m following what you’re trying to do. Something like the following should work:
$attachments = get_children( array(
'post_parent' => get_the_ID(),
'post_type' => 'attachment',
'numberposts' => 1, // show all -1
'post_status' => 'inherit',
'post_mime_type' => 'image',
'order' => 'ASC',
'orderby' => 'menu_order ASC'
) );
foreach ( $attachments as $attachment_id => $attachment ) {
echo do_shortcode( '[download]' . wp_get_attachment_url( $attachment_id ) . '[download]' );
}
Thread Starter
mundza
(@mundza)
Thanks for fast reply.. This however doesnt work.. it just prints the function in the post/contetnt. Example this shows in content [download]http://my-wallpapers.com/wp-content/uploads/2013/12/481.jpg[download] but not doing that shortcode.
Amer M.
Thread Starter
mundza
(@mundza)
this is great idea that you came out with but not working… it should but its not working dont know why .. I hope you understand what I’m trieing to do.. in short: (wallpeper site, on every post i got 1 image, your download shortcode should download that image only)
mundza
Member
Posted 10 hours ago #
Hi
i want to replace url that i NEED to provide inside the [download]and[/download] with my automatic get_attachment_url script:
$attachments = get_children( array(
'post_parent' => get_the_ID(),
'post_type' => 'attachment',
'numberposts' => 1, // show all -1
'post_status' => 'inherit',
'post_mime_type' => 'image',
'order' => 'ASC',
'orderby' => 'menu_order ASC'
) );
foreach ( $attachments as $attachment_id => $attachment ) {
echo do_shortcode( '[download]' . wp_get_attachment_url( $attachment_id ) . '[download]' );
}
this works amazing.. but not executing command
Thanks
Thread Starter
mundza
(@mundza)
ei sorry mate.. that worked i didt activated plugin before hhehe 😀 soorry again for 20000000 replies heheh 😀 thanks a lot once again 😀 very very helpfull… This is site that this plugin used on 😀 tnx
Apologies. I forgot that the URL should be first be derived before it’s used in do_shortcode()
. I tested the following and it worked. You’d of course want to change that up to fit your needs, perhaps pass a label using something like [download label="Download"]
or something. Here’s the snippet that worked for me:
$attachments = get_children( array(
'post_parent' => get_the_ID(),
'post_type' => 'attachment',
'numberposts' => 1, // show all -1
'post_status' => 'inherit',
'post_mime_type' => 'image',
'order' => 'ASC',
'orderby' => 'menu_order ASC'
) );
foreach ( $attachments as $attachment_id => $attachment ) {
$url = wp_get_attachment_url( $attachment_id );
echo do_shortcode( '[download]' . $url . '[/download]' );
}
Thread Starter
mundza
(@mundza)
Hey Drew …
I succeded with the code above it works like charm…
foreach ( $attachments as $attachment_id => $attachment ) {
echo do_shortcode( '[download]' . wp_get_attachment_url( $attachment_id ) . '[download]' );
I think bunch of people were looking for this and now its here to help ppl …
Thanks a lot one more time .. nice job 🙂