not able to use Python-WordPress-XMLRPC to add Custom Field to Job Listing at WordPress

[ad_1]

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!

[ad_2]
1 Comment
  1. Why not use the WordPress API instead? That Python package has not been managed in quite some time, so I don’t know that you’ll be able to get much help with it.

    Edit: Maybe also try deleting your comma after the dictionary that you’re appending to the list, that could be causing an issue perhaps?

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer