maxcutler / python-wordpress-xmlrpc

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

How to edit custom fields Wordpress with xmlrpc? #64

Open xmlmes opened 10 years ago

xmlmes commented 10 years ago

I can't add or edit any information in some custom fields. I speak about blog post, not another content.

Field with atribute name="url_video" I haven't problem. But for example name="data[url_video]" doesn't work to add/edit.

I think only occurs this with custom field that contains [ ]. Is there any known problem? I can't find anything in Internet. Is a bug, not possible to do or an error in code?

My Python code that works:

client = Client('http://example.com/xmlrpc.php', 'user', 'password')

fields = [ ['video_url', 100], ['video_title', 'yes'] ]

widget = WordPressPost()
widget.title = 'Widget'
widget.content = 'This is the widgets description.'
widget.custom_fields = []
for field in fields:
    widget.custom_fields.append(
        {'key' : field[0], 'value' : field[1]}
    )
widget.terms_names = {
    'category': ['MyCategory'], 
}
widget.id = client.call(posts.NewPost(widget))

My Python code that doesn't works:

client = Client('http://example.com/xmlrpc.php', 'user', 'password')

fields = [ ['data[video_url]', 100], ['video_title', 'yes'] ]

widget = WordPressPost()
widget.title = 'Widget'
widget.content = 'This is the widgets description.'
widget.custom_fields = []
for field in fields:
    widget.custom_fields.append(
        {'key' : field[0], 'value' : field[1]}
    )
widget.terms_names = {
    'category': ['MyCategory'], 
}
widget.id = client.call(posts.NewPost(widget))
Emad-AiDev commented 9 years ago

Hello Did you get any answer ? I would like to update mine but no idea if that works this way!

xmlmes commented 9 years ago

I changed the theme, I suppose no exist a solution

savex83 commented 5 years ago

You can do something like this:

First save your post, than update it

widget.id = wp.call(posts.NewPost(widget)) widget.custom_fields = [] for k, v in custom_fields_dict.items(): widget.custom_fields.append({'key': k, 'value': v}) out = wp.call(EditPost(widget.id, widget))