Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Media access - store ID of media, not just URL #88

Open
nimmolo opened this issue Apr 24, 2014 · 2 comments
Open

Media access - store ID of media, not just URL #88

nimmolo opened this issue Apr 24, 2014 · 2 comments

Comments

@nimmolo
Copy link

nimmolo commented Apr 24, 2014

$wpalchemy_media_access stores the image URL, but I don't see the media's attachment ID being stored in the meta anywhere.

The ID is useful for all kinds of WP functions though - it would be good to have.

Unfortunately I don't know how to add this, but I would like to learn.

@nimmolo nimmolo changed the title Media access - stores ID of media attachment? Media access - store ID of media, not just URL? Apr 24, 2014
@nimmolo nimmolo changed the title Media access - store ID of media, not just URL? Media access - store ID of media, not just URL Apr 24, 2014
@nimmolo
Copy link
Author

nimmolo commented May 1, 2014

Update: it appears poster Dameian on farinspace wrote a javascript fix for this in 2011(!!!) that didn't make it into the code.

Also the wonderful helgatheviking posted a rewrite of the form field with image preview using the source URL, which is the only thing stored. This requires a constant WPALCHEMY to be defined elsewhere.

I will test and report if these fixes are still working …
UPDATE - They still work, but ...

The ideal solution, it seems to me, would be to store an entire post object array for the media, like ID, URL, width, height, etc. so it can be accessible in a similar manner to post thumbnails. I wish I knew how to do this. (:

@ssuess
Copy link

ssuess commented Jun 14, 2014

Just in case this helps someone else, I was able to work around this problem with this bit of code in my loop:

<?php if ($link['imgurl']) {
global $wpdb;
$result = $wpdb->get_row( "SELECT * FROM  $wpdb->posts WHERE post_parent = ".get_the_ID()." and guid ='".$link['imgurl']."'");
if($result) { 
 echo wp_get_attachment_image_src($result->ID,'my-image-size'); 
} ?>

They key is to get a unique value for each possible attachment if there is more than one, and that can be accomplished using the guid field in the posts table. Sure, it is another DB call, but not an especially heavy one. Worked for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants