Assistance Needed: Creating WordPress Post with Rank Math Metadata via REST API

#703660
  • Resolved Anonymous
    Rank Math free

    I am seeking assistance in programmatically creating a WordPress post with Rank Math metadata using the WordPress REST API. Here are the details:

    Steps Taken:

    I am using the WordPress REST API endpoint for creating a new post: /wp-json/wp/v2/posts.
    Authentication is done using HTTP Basic Authentication

    While successfully creating a post, I am facing difficulties in including Rank Math metadata such as title, description, and focus keyword in the post creation process.

    I kindly request guidance on how to include Rank Math metadata (title, description, focus keyword) in the post creation request using the WordPress REST API. Are there specific Rank Math API endpoints or parameters that need to be included in the request payload?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hello,

    I apologize for the inconvenience you’re experiencing. While the WordPress REST API endpoint /wp-json/wp/v2/posts allows you to create a new post, including Rank Math metadata such as title, description, and focus keyword in the post creation process requires additional steps.

    Rank Math’s metadata is not directly included in the WordPress REST API. However, you can retrieve the metadata using Rank Math’s REST API endpoint `/wp-json/rankmath/v1/getHead?url=https://rankmath.com/kb/wordpress-hooks-actions-filters/#functions-php-file This will return the meta tags added by Rank Math for the specified URL in a JSON format.

    To include Rank Math metadata in the post creation request, you would need to retrieve the metadata using the Rank Math REST API endpoint and then manually add it to your post creation request using the WordPress REST API.

    If you have any further questions or need assistance with this process, please feel free to reach out to our support team directly from here, and we’re always here to help.

    Thank you for reaching out to us!

    Sources:
    How to Enable Headless CMS Support in Rank Math? » Rank Math
    How to Automate the Insertion of Focus Keyword » Rank Math
    Rank Math General Settings

    Hello,

    You can use the following meta keys to add the metadata using the API:

    rank_math_title
    rank_math_description
    rank_math_focus_keyword

    Please make sure that the meta keys are registered inside the postmeta table.

    You can learn how to register the meta key in this example here: https://wordpress.stackexchange.com/questions/380513/add-post-meta-fields-when-creating-a-post-using-wordpress-rest-api

    Hope that helps.

    Thank you.

    Anonymous
    Rank Math free

    I tried this solution but as previously I mentioned, It successfully created a post but not with rank math metadata

    Hello,

    Did you register the Rank Math custom postmeta data? If you don’t register those fields following the example tutorial shared above you won’t be able to add them during the saving process.

    Please note that we don’t have any custom-built support for the WordPress REST API and to accomplish this so our support team can’t help you create the custom code necessary for this. We can just explain what is required to make this work from previous experience.

    Don’t hesitate to get in touch if you have any other questions.

    Hello,

    Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.

    If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.

    Thank you.

Viewing 4 replies - 1 through 4 (of 4 total)

The ticket ‘Assistance Needed: Creating WordPress Post with Rank Math Metadata via REST API’ is closed to new replies.