Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have many posts with a unique reference for a custom field [123456], over time I would like an administrator to upload a single image that matches the custom field ie > 123456.jpg

I would then like to use a condition in the loop that says if file exists (123456.jpg) that matches the custom field (123456) then use that image for all posts with that custom field...

I cant use the Media library because the folder structure is chronological, is there another way?

share|improve this question
add comment

1 Answer

You can still use the media library and either reference the attachment's ID or add a postmeta to the attachment containing your id.

You could even make this a bit easier by using a custom taxonomy instead of custom field. Add your numbers as terms to that taxonomy. Also register the taxonomy to apply to attachments. Then write a bit of code that whenever the post has (a) term(s) in that taxonomy finds the attachments that also have a the same term(s) in that taxonomy. This would even allow you to have both, multiple of your numbers for a post and multiple images per number, leading to all kinds of possible combinations.

share|improve this answer
1  
wow that made my head spin, don't understand that without seeing the code –  erichmond Feb 24 '11 at 23:06
    
Sorry, too busy to write it for you. But i'll try to make it a bit clearer...just imagine your custom taxonomy would be the tags. So you add tags capability to attachments (google for `wordpress register taxonomy for object'). Now instead of adding your 'special number' as a custom field, you add it as a tag. Admin then adds the same number as a tag to attachments. The only custom code you need then goes something like this: - fetch tags for post, - for each tag, fetch the attachment(s) with the same tag, - for each found attachment, get the file url. WP has functions for all of that. –  wyrfel Feb 25 '11 at 1:03
    
Yes that makes perfect sence, using The taxonomy rather than a custom field, having given it more thought I'm not actually sure I've thought of the best solution. 20 post might need to use the same image but I want the user to upload 1 image and the posts to use it if it exists without the user having to go into each post and add the taxonomy. –  erichmond Feb 26 '11 at 8:39
    
@erichmond Well, if you add the taxonomy or a custom field is the same in the end, isn't it. You'll have to write some code to do it automatically in either case. –  wyrfel Feb 26 '11 at 9:25
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.