Bird
0
0

Given this code snippet, what will be the output? $term = get_term_by('slug', 'fiction', 'genre'); echo $term->term_id;

medium📝 Predict Output Q5 of 15
Wordpress - Custom Post Types and Taxonomies
Given this code snippet, what will be the output? $term = get_term_by('slug', 'fiction', 'genre'); echo $term->term_id;
AThe ID of the 'fiction' term in 'genre' taxonomy
BThe slug 'fiction'
CError: Undefined variable
DEmpty output
Step-by-Step Solution
Solution:
  1. Step 1: Understand get_term_by() usage

    get_term_by() fetches a term object by a field, here 'slug' with value 'fiction'.
  2. Step 2: Access term_id property

    echo $term->term_id outputs the ID of the found term.
  3. Final Answer:

    The ID of the 'fiction' term in 'genre' taxonomy -> Option A
  4. Quick Check:

    get_term_by() returns term object; term_id is its ID [OK]
Quick Trick: Use get_term_by('slug', slug, taxonomy) to get term object [OK]
Common Mistakes:
  • Expecting slug output instead of ID
  • Not checking if term exists before echo

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Wordpress Quizzes