WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Select Image from Media Library for custom field (13 posts)

  1. darksummenors
    Member
    Posted 1 year ago #

    I'm looking for a plugin/code that will allow me to easily insert image paths of images from the media library into custom fields. Sort of a gallery that when clicked drops the img url into the custom field. making a slider for the frontpage with an admin panel. you insert the img url for the slides. i want to make a button for uploaded images. using wordpress 3.4.2

    Does anyone know of any out there like this? Searched my but off... :P

    Screenshot:
    http://img819.imageshack.us/img819/5629/slideradmin.jpg

    Regards
    Gydo

  2. Marty Spellerberg
    Member
    Posted 1 year ago #

    @darksummenors If I understand you right, it sounds similar to what I was working on last week. Open up the media library modal, select an image and have the URL inserted into a field?

    My first bit of success came from this link:
    http://sltaylor.co.uk/blog/hijacking-the-wordpress-media-library-overlay/

    Then I was able to take it further with this:
    http://mikejolley.com/2012/12/using-the-new-wordpress-3-5-media-uploader-in-plugins/

    If this is the correct path let me know I can share the code I ended up using, though it's for 3.5.

  3. darksummenors
    Member
    Posted 1 year ago #

    Yea that is precisely what i want. If you see the screenshot you see that i ask for an image url. The people that gonna use this plugin on our company arent that handy so i thought it would be nice that they only have to select the image they uploaded.

    Gonna check your links, hope it works in 3.4.2 cause it says the new wordpress 3.5 media uploader

    Regards,
    Gydo

  4. darksummenors
    Member
    Posted 1 year ago #

    I'm gonna check your links further now. I was still tweaking the plugin and slider on front and admin panel evry settings and stuff are installed. i really need to learn to use arrays. cause moost plugins are build with arrays and i am building it with php and html. looks unprofessional when i see other plugins.

    (also sorry for my bad English)

    Friendly regards,
    Gydo

  5. darksummenors
    Member
    Posted 1 year ago #

    The only problem i still having is how do i get that id. Because the plugin you sended uses image by id. don't wan't img preview (that is getting made by js). Main issue is this.

    Source

    <?php
    $attachment_id = 8; // attachment ID
    
    $image_attributes = wp_get_attachment_image_src( $attachment_id ); // returns an array
    ?> 
    
    <?php echo $image_attributes[0]; ?>

    like you see i need an ID the id is in javascript.

  6. Marty Spellerberg
    Member
    Posted 1 year ago #

    @darksummenors

    The URL will be inserted into the text field using JavaScript. I've posted a sample for you here:

    https://gist.github.com/halfempty/4771812

  7. darksummenors
    Member
    Posted 1 year ago #

    thank you for your reply
    i've got it working with the first plugin you have send.
    but it works only for 1 field. at the moment.
    so i will going to check gydo.js :)

    Friendly regards,
    Gydo

  8. darksummenors
    Member
    Posted 1 year ago #

  9. Marty Spellerberg
    Member
    Posted 1 year ago #

    Way to go!

  10. dan_mcclellan
    Member
    Posted 6 months ago #

    ok. I'm having a similar issue.

    I want a different banner on each of my pages. It all works except the links show up broken. I'm thinking that the attachment id's don't work but the actual image urls will.

    My code is

    <div class="banner">
    				<?php if(get_post_meta($post->ID, 'banner', true)) : ?>
    				<img src="<?php echo get_post_meta($post->ID, 'banner', true); ?>" />
    				<?php else : ?>
    				<?php the_title(); ?>
    				<?php endif; ?>
    			</div>

    What should be different to echo the image url rather than ID?
    (I'm a php newb)

  11. bcworkz
    Member
    Posted 6 months ago #

    Hi Dan,
    If the banner attachment id is stored in post meta, you can use wp_get_attachment_url() to get the URL associated with that ID. I'm assuming your current HTML page source is simply showing an integer as the img src attribute?

    If so, something like this should work for you:
    <img src="<?php echo wp_get_attachment_url( get_post_meta( $post->ID, 'banner', true )); ?>" />

    If you have additional questions, please start a new topic. Adding on to other's threads is highly discouraged in these forums. It also ensures more people will see you question :)

  12. darksummenors
    Member
    Posted 6 months ago #

    I'll copy my entire code in here. Please don't watch how it has been coded because its pretty messy.

    [ 700+ lines of code moderated, that's just way too much. For that many lines of code please use pastebin.com instead. ]

    Hope you can use some of this messy stuff.

    Gydo

  13. dan_mcclellan
    Member
    Posted 6 months ago #

    I ended up getting it to work by using a text field & pasting in the image url. It is a lot of work though, so I'll probably follow bcworkz advice next week when things slow down (going live tonight!)

Topic Closed

This topic has been closed to new replies.

About this Topic