Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Field not working #161

Open
kawsarlog opened this issue May 25, 2024 · 0 comments
Open

Custom Field not working #161

kawsarlog opened this issue May 25, 2024 · 0 comments

Comments

@kawsarlog
Copy link

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant