John Davidson

php - Pass term_id value in wp_insert_term() function

0 comments
Message:


I wanted to pass custom term_id in wp_insert_term() function in wordpress


Currently it accepts:


wp_insert_term( string $term, string $taxonomy, array|string $args = array() )

The reason is simple, i want to import thousands of terms from Drupal and going to use this function to do it, and wanted to keep the term_id same as Drupal tid.



My Answer:
Unfortunately, it is not possible to pass a custom term_id value in the wp_insert_term() function in WordPress. The term_id is automatically generated by WordPress when a new term is inserted into the database.

If you want to keep the term_id the same as the Drupal tid, you will need to come up with a different strategy for importing the terms. One possible solution is to create a custom field in WordPress to store the Drupal tid value and then use that field to map the Drupal tid to the WordPress term_id.

Alternatively, you could create a custom script to import the terms from Drupal and manually set the term_id value in the database. However, this is not recommended as it can lead to conflicts and issues with the WordPress database structure.

Overall, it is best to work within the constraints of the WordPress API and find a different approach to importing your terms while maintaining the desired term_id values.

Rate this post

3 of 5 based on 5664 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us