I'm migrating some posts from another source to WordPress, specifically to a theme/plugin called Madara, which has some specific taxonomies. I'm using wp_insert_post() to create the post, everything works fine until I try to set the taxonomies, I tried to set the taxonomies directly via the tax_input array on the wp_insert_post(), even with a post_auhtor defined and the wp_set_current_user() set, it didn't work.

I also tried with the wp_set_object_terms() after creating the post, but I've getting Invalid taxonomy error.

this is a sample screenshot taken from the "Quick Edit" request on admin panel, basically the same way I'm defining in on wp_insert_post()

enter image description here

Important: This is not a regular wordpress plugin, it is a cron job that's just using WordPress functions.

Wordpress files being included in the cron code:

require_once "../../../wp-load.php";
require_once "../../../wp-admin/includes/taxonomy.php";
require_once "../../../wp-admin/includes/file.php";
require_once "../../../wp-admin/includes/image.php";
require_once "../../../wp-admin/includes/media.php";

How can I add those taxonomies?

  • Can you confirm that the cron job script is loading what is required to register the custom taxonomy and connect it to the core post post type? When you say cron job do you mean WP_Cron or command line cron? Please note StackOverflow guidelines for asking good questions. They discourage use of images to present code and output from debugging, warnings or errors. Text should be used.
    – kofeigen
    Nov 8, 2023 at 0:10
  • A command line cron job, just like php code.php.... I'll update the question with the loaded Wordpress files that I'm using in the cron Nov 8, 2023 at 0:12
  • I do not see the call to the register_taxonomy() function anywhere. I'm guessing this function call is buried in the code for the Madara theme. How do you know this cron command line script is loading the Madara theme?
    – kofeigen
    Nov 8, 2023 at 0:20
  • The theme installs some taxonomies before hand, it already exists on the DB. I'm having a hard time trying to understand why I have to register it if it already is on db, I thought this taxonomy creation was just like categories. Nov 8, 2023 at 1:40
  • Do i have to call register_taxonomy before creating it? even if it already exists? Nov 8, 2023 at 1:40


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.