Join the Soledad Facebook Users Group here
for Share, assistance, discussion, and Updates related to Soledad WordPress Theme.

If you can't create a new ticket - you can send us an email via our contact form and we will get back to you.

Okay
  Public Ticket #2814395
Unable to set category in Post from PHP
Closed

Comments

  • calvinteoh started the conversation

    I have created a new category named World News and the slug name is worldnews. 

    I have a PHP code that would generate a post and insert the post to Wordpress. However, when I enter the category using the "post_category" function with "worldnews", I am not able to update the category to the post. This cause the post to have a non-category post. 

    Can you feedback, on what is the right way to enter the category from PHP for this theme? Do I need to use some ID value?

  •  2,615
    PenciDesign replied

    Hi,

    Please read this document about WP Insert Post: https://developer.wordpress.org/reference/functions/wp_insert_post/

    The "post_category" only accepts category ID, so please find the Category ID of the category then tries again.

    Regards,
    PenciDesign.


  • calvinteoh replied

    Thanks for the feedback! I managed to solve this based on the feedback you provided.