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'm setting up a real estate website, which i make listings using a custom post type 'listings' in which I have multiples metaboxes for beds, baths, and all other informations.

I use a plugin to import these posts because listings are generated from a 3d party software, (XML file with Xpaths), as far everything when ok importing listings.

The BUT is that the theme inserts images 'attached to the post' '_wp_attach_file ... file'.

The XML makes easy to get the paths to images, but I can't figured out how to make them 'be attached' to the post to load up.

Is it possible to attach them using custom fields?

(i need to do this for almost 500 posts through WP ALL IMPORT - XML XPath importer plugin - which i can insert custom_fields and metaboxes lines)

If someone knows how to do the trick, please share your secret

Many thanks

share|improve this question
add comment

1 Answer

I would recommend just modifying the single-listings.php template file to output the gallery directly:

<?php echo do_shortcode( '[gallery] ); ?>

That way, for all the images that have been imported and attached to a given CPT, they weill be output just as if you had placed a [gallery] shortcode in the post_content for each post.

Edit

If you have post metadata that contains image URL paths, and you want to upload/attach those images to the post, then have a look at media_sideload_image() (or, in 3.5, wp_sideload_image()).

share|improve this answer
    
I does that already, the problem is that there is no attached files the CPT. I'm trying to figure out how to attach them. I tried to set the path to the file with custom field for each post: _wp_attached_file -> DIR/uploads/2012/IMAGE.JPG and i doesn't work, any idea of what i'm doing wrong? –  Furtado Nov 20 '12 at 20:05
    
Okay, I was confused by the wording of the question. So you don't actually have images attached to the post, but rather you have custom post metadata for the images, with meta keys like _wp_attach_file? –  Chip Bennett Nov 20 '12 at 20:12
    
I manually upldd images through ftp (16000 images), those imgs are the listings imgs (500 listings). The theme, only calls images when they are attached to the CPT. I cant manage to add them manually (post by post), so I have to find a way to attach them when I do the import. Importing the listings I can set custom fields for each, using the XML to provide the path. I browsed up the db to see an example of an attached file looks like and it shows a meta_key and meta_value (key-> wp_attached_file | value-> 2012/11/IMAGE.JPG). So I am trying to _attach it like that. but it isnt working. –  Furtado Nov 20 '12 at 20:30
    
I don't know if the meta_id or post_id has something to do with that, I really don't understand much about it. Is those path's case sensitive? (thanks for your attention) –  Furtado Nov 20 '12 at 20:32
    
How can i do this media_sideload? –  Furtado Nov 20 '12 at 20:36
show 6 more comments

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.