maxcutler / python-wordpress-xmlrpc

Python library for WordPress XML-RPC integration
http://python-wordpress-xmlrpc.rtfd.org
MIT License
380 stars 129 forks source link

How to attach multiple images to a WordPressPost object? #120

Closed loxator closed 6 years ago

loxator commented 6 years ago

Hi everyone,

I am trying to attach multiple images to a single WordPressPost object. I have successfully uploaded the attachments to the media library, but now I want to attach these images to a 3d-flip-book type of widget. I am able to create the widget, and add it to the post, which results in an empty 3d-flip-book on my website. Then I manually populate the flipbook, and I want to do this via code. So, how do I attach multiple images to the 3d-flip-book that I have created? Thanks!

n3storm commented 6 years ago

You have to understand how your flipbook wordpress plugin works in order to work with them. Have a look at database is usuarlly a good idea.

Most wordpress plugins use custom post types and custom fields: http://python-wordpress-xmlrpc.readthedocs.io/en/latest/examples/posts.html#custom-post-types

Cheers.

loxator commented 6 years ago

@n3storm

Thanks for the help! I have tried looking into what you said but still can't figure it out. This is the plugin that I am trying to add images to. I tried seeing the custom_fields of my post that I already uploaded, using post.custom_fields but that produced an output like below, which I couldn't understand

[{'id': '7011', 'key': '3dfb_controlProps', 'value': 'a:1:{s:7:"actions";a:3:{s:7:"cmdSave";a:1:{s:7:"enabled";s:4:"auto";}s:8:"cmdPrint";a:1:{s:7:"enabled";s:4:"auto";}s:13:"cmdSinglePage";a:2:{s:7:"enabled";s:4:"auto";s:6:"active";s:4:"auto";}}}'}, {'id': '7009', 'key': '3dfb_data', 'value': 'a:4:{s:9:"pdf_pages";s:1:"0";s:7:"post_ID";i:0;s:4:"guid";s:0:"";s:19:"pages_customization";s:3:"all";}'}, {'id': '7010', 'key': '3dfb_props', 'value': 'a:13:{s:6:"height";s:4:"auto";s:5:"width";s:4:"auto";s:7:"gravity";s:4:"auto";s:11:"cachedPages";s:4:"auto";s:19:"renderInactivePages";s:4:"auto";s:27:"renderInactivePagesOnMobile";s:4:"auto";s:19:"renderWhileFlipping";s:4:"auto";s:18:"pagesForPredicting";s:4:"auto";s:12:"preloadPages";s:4:"auto";s:3:"rtl";s:4:"auto";s:5:"sheet";a:9:{s:13:"startVelocity";s:4:"auto";s:15:"cornerDeviation";s:4:"auto";s:11:"flexibility";s:4:"auto";s:14:"flexibleCorner";s:4:"auto";s:7:"bending";s:4:"auto";s:4:"wave";s:4:"auto";s:11:"widthTexels";s:4:"auto";s:12:"heightTexels";s:4:"auto";s:5:"color";s:4:"auto";}s:5:"cover";a:12:{s:13:"startVelocity";s:4:"auto";s:11:"flexibility";s:4:"auto";s:14:"flexibleCorner";s:4:"auto";s:7:"bending";s:4:"auto";s:4:"wave";s:4:"auto";s:11:"widthTexels";s:4:"auto";s:12:"heightTexels";s:4:"auto";s:5:"color";s:4:"auto";s:13:"binderTexture";s:4:"auto";s:5:"depth";s:4:"auto";s:7:"padding";s:4:"auto";s:4:"mass";s:4:"auto";}s:4:"page";a:10:{s:13:"startVelocity";s:4:"auto";s:11:"flexibility";s:4:"auto";s:14:"flexibleCorner";s:4:"auto";s:7:"bending";s:4:"auto";s:4:"wave";s:4:"auto";s:11:"widthTexels";s:4:"auto";s:12:"heightTexels";s:4:"auto";s:5:"color";s:4:"auto";s:5:"depth";s:4:"auto";s:4:"mass";s:4:"auto";}}'}, {'id': '7008', 'key': '3dfb_thumbnail', 'value': 'a:2:{s:4:"data";a:1:{s:7:"post_ID";s:1:"0";}s:4:"type";s:4:"auto";}'}, {'id': '7007', 'key': '3dfb_type', 'value': 'custom'}]

From the above output, I can that all of them are 3d-flip-book properties but the values make no sense to me :S

Also, what do you mean by looking at database? I didn't understand that part. Thanks for your help once again!

n3storm commented 6 years ago

All metadata around a wp post is stored in database table called "postmeta". Your approach is also right.

Data you pasted is a PHP serialized data: http://php.net/manual/es/function.serialize.php

This is a very specific issue about a third party plugin and I cannot help you further and this will not the proper place to solve it.

Also remember you can create your own php functions to interact via xmlrpc (http://python-wordpress-xmlrpc.readthedocs.io/en/latest/examples/custom-methods.html) But again, you have to understand how does the plugin work to program a custom php method.

loxator commented 6 years ago

Thank you for the tips and all your help! Much appreciated 😄