I have created a script that posts to my website when I run it (see code below) and everything works as it should, except I cannot seem to set the template for pages that I create.
from wordpress_xmlrpc import Client
from wordpress_xmlrpc.methods import posts, pages
from wordpress_xmlrpc import WordPressPage
client = Client(...)
page = WordPressPage()
page.template = 'template_name.php'
page.parent_id = '206'
page.title = 'Test'
page.slug = 'rrr'
page.content = 'Some text goes here'
page.post_status = 'publish'
page.id = client.call(posts.NewPost(page))
I found this issue posted at the repository (https://github.com/maxcutler/python-wordpress-xmlrpc/issues/44), and I tried using the alternative method:
page.wp_page_template = 'template_name.php'
I’ve also tried the names of the templates and other variations. I also find that my template(s) when I use the GetPageTemplates code:
templates = client.call(pages.GetPageTemplates())
All of my templates gets shown here.
Anyone had any success using this setting?
Seems a bug of wordpress_xmlrpc.
wordpress_xmlrpc converts field ‘template’ -> ‘wp_page_tempalte’ but its wrong.
Should be converted to ‘page_template’ (without wp_ prefix).
“class-wp-xmlrpc-server.php” then converts field of post data from ‘page_template’ to ‘wp_page_template’.
So wordpress_xmlrpc should send
page_template
notwp_page_template
.wordpress_xmlrpc converts
template
towp_page_template
before post, so:use ‘template’
page.template = 'template_name.php'
patch wordpress.py like:
It worked.