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

Custom Field not working #161

Open kawsarlog opened 3 months ago

kawsarlog commented 3 months ago

I tried to add a custom field to WordPress 6.5.3 using the python-wordpress-xmlrpc package, but I'm not sure why it's not working right now. My code is below.

from wordpress_xmlrpc import Client, WordPressPost
from wordpress_xmlrpc.methods.posts import NewPost, EditPost
from wordpress_xmlrpc.methods.posts import DeletePost
from wordpress_xmlrpc.methods import taxonomies
from wordpress_xmlrpc.methods.taxonomies import GetTerms

# Authenticate with your WordPress site
wp_url = 'https://example.com/xmlrpc.php'
wp_username = 'username'
wp_password = 'password'
wp_client = Client(wp_url, wp_username, wp_password)

# Creating a new post
job_post = WordPressPost()
job_post.title = 'Job Title'
job_post.content = 'Job Content'
job_post.post_status = 'draft'
job_post.post_type = 'job_listing'

# Assigning location terms to the post
job_post.terms_names = {'job_listing_location': ['Chicago']}

job_post.custom_fields = []
# Add multiple custom fields to the post
job_post.custom_fields.append(
    {'key': '_job_max_salary', 'value': 50000}, 
)

# Submit the new post to WordPress
wp_post_id = wp_client.call(NewPost(job_post))
print("Job listing created successfully with ID:", wp_post_id)

The post was created successfully when I ran this, but no custom field data!