[Python] How to add Multiple field data with WordPress Rest API and Python

Discussão em 'Python' iniciado por Stack, Dezembro 17, 2024.

  1. Stack

    Stack Membro Participativo

    I want to add a featured image, and since I am using Yoast SEO, I also want to add a focus keyphrase, SEO title, and meta description using the Python REST API, but I don't know how to proceed further.

    import requests
    import json
    import base64

    url = "https://exampleurl.com/wp-json/wp/v2/posts"
    user = "Username"
    password = "application password"
    credentials = user + ':' + password
    token = base64.b64encode(credentials.encode())
    header = {'Authorization': 'Basic ' + token.decode('utf-8')}
    post = { 'title' : 'Test WP-API',
    'content' : 'This is my first post created using restAPI',
    'status' : 'draft',
    }
    responce = requests.post(url , headers=header, json=post)

    print(responce.json())

    Continue reading...

Compartilhe esta Página