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

Cannot set post date #116

Closed mplorentz closed 6 years ago

mplorentz commented 6 years ago

Hi, I'm trying to create a new post with a publish date in the past. The post is created just fine, but the publish date shows as the time the post was created and not the date I set. I can edit the post date to be in the past in the Wordpress GUI so I think this should be possible.

I have tried setting the date before creating the post and after. Here is my code for the latter:

client = Client(url, username, password)
post = WordPressPost()
post.title = title
post.content = body
post.post_status = 'publish'
post.id = client.call(posts.NewPost(post))

post.date = date
post.date_modified = date
client.call(posts.EditPost(post.id, post))

Is there some reason that setting the publish date to be in the past is not possible via the xmlrpc API, or am I doing something wrong?

alexdarling commented 6 years ago

I can't reproduce this issue. Could it be how you are writing the date? It should be in datetime format. The code below works for me.

from wordpress_xmlrpc import Client, WordPressPost
from datetime import datetime

client = Client(url, username, password)
post = WordPressPost()
post.title = 'Title Foo'
post.content = 'Content Bar'
post.post_status = 'publish'
post.id = client.call(posts.NewPost(post))

post.date = datetime(2016,1,1)
post.date_modified = datetime(2016,1,1)
client.call(posts.EditPost(post.id, post))

From there, visiting the post shows that the date is 2016-01-01.

mplorentz commented 6 years ago

Actually I just ran my code again and it works just fine... must've been a problem with my install which has been resolved. Thanks for taking a look!

johnson329 commented 6 years ago

thx