• Resolved mundza

    (@mundza)


    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 wp_get_attachment_url( $attachment_id );
    }
    ?>

    I want to use wp_get_attachment_url( $attachment_id ) instead of [download]ThisUrl[/download]

    I want to use this download button on every post.. and i want it to be automatic.. i found how to get attachment URL .. now i need your suggestion.. My site is: and I want it to be Implemented in Content with all the other autotext i got..

    Thanks in advance
    Amer M.

    https://www.ads-software.com/plugins/download-shortcode/

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Drew Jaynes

    (@drewapicture)

    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]https://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

    Plugin Author Drew Jaynes

    (@drewapicture)

    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 ??

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Add my custom link’ is closed to new replies.