Hi,
the Ads are WordPress custom post types so it is the easiest to create the ads using the WP native wp_insert_post() and add_post_meta() functions.
One other way to do that would be to use the Adverts_Post::save() method, how to use it you can see in the wpadverts/includes/class-shortcode-adverts-add.php file on lines about 374 to 400.
The code does not show how to add images to the gallery, but the images in the gallery are WP post attachments so once you have the Ad saved you can add attachments to it using the wp_insert_attachment() function.
Hope this helps.
Hi, Thank you for clarification.
But I still not understand something.
You said for gallery it use native WP post attachments.
Do we need to add any meta to this attachment?
Because when I see this part in your plugin:
Adverts_Gallery_Helper->load_attachments()
It seems to only load attachment if it contains certain meta in it.
Will it work if we just use importer plugin? (they will not add this meta to attachment)
If it wont work, What all the meta needs to exist in the image attachment?
Hi,
yes, each attachment should have 2 meta fields that connect it to a correct field in the [adverts_add] form, if you have attachments in the gallery field only then it should be just
update_post_meta( $attach_id, "wpadverts_form", "advert" );
update_post_meta( $attach_id, "wpadverts_form_field", "gallery" );