How to “Make Term Primary via API”

#592813
  • Resolved Bradley Duncan
    Rank Math free

    I’m trying to add posts that are displayed on our website from the wordpress API. However whenever a post is created, the “Make Term Primary” radio button isn’t selected on the category. As a result, the post does not appear on the site.

    Steps to reproduce:
    Create an API request to the wordpress posts endpoint with a category. See how the category does not get selected as “Primary Term”.

    I tried something like this and it still doesn’t work:

    $postData = array(
    ‘title’ => $sai_title,
    ‘content’ => $sai_body,
    ‘categories’ => array(33),
    ‘status’ => ‘publish’,
    ‘meta’ => array(
    ‘rank_math_primary_category’ => 33
    )
    );

Viewing 1 replies (of 1 total)
  • Hello,

    Thank you for your query and we are so sorry about the trouble this must have caused.

    When performing the REST API call with that code do you see the value rank_math_primary_category in the postmeta table?

    We ask this because that format alone won’t help to add the metadata into the database correctly. You need to create a loop that goes through the meta array and adds each value to the database similar to what is explained here: https://github.com/NBY/post-meta-data-with-rest-api/blob/main/post-meta-data-with-rest-api.php

    Hope this helps clarify the situation.

    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 1 replies (of 1 total)

The ticket ‘How to “Make Term Primary via API”’ is closed to new replies.