Bird
0
0

What is wrong with this code snippet? wp_insert_term('Adventure', 'genre', ['parent' => 5]); It returns a WP_Error instead of inserting the term.

medium📝 Debug Q6 of 15
Wordpress - Custom Post Types and Taxonomies
What is wrong with this code snippet? wp_insert_term('Adventure', 'genre', ['parent' => 5]); It returns a WP_Error instead of inserting the term.
AThe parent parameter should be a string, not an integer
BThe parent term ID 5 does not exist in 'genre' taxonomy
CThe taxonomy 'genre' is not registered
DThe term name 'Adventure' is invalid
Step-by-Step Solution
Solution:
  1. Step 1: Check parent term existence

    wp_insert_term() fails if the parent term ID does not exist in the taxonomy.
  2. Step 2: Validate other parameters

    Term name and taxonomy are valid; parent must be existing term ID.
  3. Final Answer:

    The parent term ID 5 does not exist in 'genre' taxonomy -> Option B
  4. Quick Check:

    Parent term must exist to avoid WP_Error [OK]
Quick Trick: Ensure parent term exists before assigning in wp_insert_term() [OK]
Common Mistakes:
  • Assuming parent ID can be any number
  • Ignoring taxonomy registration status

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Wordpress Quizzes