Custom Taxonomies Flashcards

1
Q

Q: What is a taxonomy in WordPress?

A

A: A way to group posts or custom post types together based on shared characteristics.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Q: What are the two default taxonomies in WordPress?

A

A: Categories and tags.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Q: What is a custom taxonomy?

A

A: A user-defined taxonomy for grouping custom post types or posts.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Q: What function is used to register a custom taxonomy?

A

A: register_taxonomy().

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Q: What is the required parameter for register_taxonomy()?

A

A: The $taxonomy name (e.g., genre).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Q: What does the labels argument define in register_taxonomy()?

A

A: Text labels for the taxonomy in the WordPress admin interface.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Q: What does the hierarchical argument control?

A

A: Whether the taxonomy behaves like categories (true) or tags (false).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Q: What is the public argument used for in register_taxonomy()?

A

A: To determine if the taxonomy is accessible on the front end and admin.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Q: What does the show_ui argument do?

A

A: Determines whether the taxonomy appears in the WordPress admin UI.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Q: What is the rewrite argument used for?

A

A: To customise the URL structure for the taxonomy terms.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Q: How do you set the singular label for a custom taxonomy?

A

A: Use the singular_name key in the $labels array.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Q: How do you set the plural label for a custom taxonomy?

A

A: Use the name key in the $labels array.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Q: What label is used for the “Add New Term” button?

A

A: add_new_item.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Q: What label is used for editing a term?

A

A: edit_item.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Q: How do you set the label for the taxonomy admin menu?

A

A: Use the menu_name key in the $labels array.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Q: How do you associate a custom taxonomy with a custom post type?

A

A: Use the $object_type parameter in register_taxonomy().

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Q: Can a taxonomy be shared across multiple post types?

A

A: Yes, by passing an array of post types to the $object_type parameter.

18
Q

Q: How do you link a taxonomy to multiple custom post types?

A

register_taxonomy( ‘genre’, array( ‘books’, ‘movies’ ), $args );

19
Q

Q: What does the taxonomies argument in register_post_type() do?

A

A: Associates an existing taxonomy with a custom post type.

20
Q

Q: How do you make a custom taxonomy REST API compatible?

A

A: Set the show_in_rest argument to true in register_taxonomy().

21
Q

Q: How do you display the terms of a taxonomy associated with a post?

A

A: Use the the_terms() function.

22
Q

Q: What is the default template file for taxonomy archives?

A

A: taxonomy-{taxonomy}.php.

23
Q

Q: What is the fallback template for taxonomy archives?

A

A: archive.php.

24
Q

Q: How do you retrieve all terms of a taxonomy?

A

A: Use the get_terms() function.

25
Q

Q: What is the purpose of the wp_get_post_terms() function?

A

A: To retrieve terms associated with a specific post.

26
Q

Q: How do you customise the permalink structure for a taxonomy?

A

A: Use the rewrite argument in register_taxonomy().

27
Q

Q: How do you add custom fields to taxonomy terms?

A

A: Hook into the edit_term or create_term actions and save fields with update_term_meta().

28
Q

Q: How do you display a custom taxonomy dropdown in the admin list view?

A

A: Hook into the restrict_manage_posts action.

29
Q

Q: How can you sort posts by taxonomy terms in the admin?

A

A: Hook into the pre_get_posts action to modify the query.

30
Q

Q: How do you add custom metaboxes for taxonomy terms?

A

A: Use the add_meta_boxes hook and customise the metabox for your taxonomy.

31
Q

Q: What is the capabilities argument in register_taxonomy()?

A

A: Specifies the capabilities required to manage the taxonomy.

32
Q

Q: What does the meta_box_cb argument do?

A

A: Defines the callback function for displaying the taxonomy metabox in the admin.

33
Q

Q: How do you make a custom taxonomy non-hierarchical?

A

A: Set the hierarchical argument to false.

34
Q

Q: How can you limit the number of terms selectable for a taxonomy?

A

A: Use JavaScript to restrict the selection in the admin interface.

35
Q

Q: How do you modify the query for a taxonomy archive page?

A

A: Use the pre_get_posts action and check for the taxonomy query.

36
Q

Q: Why should you prefix taxonomy names?

A

A: To avoid naming conflicts with other plugins or themes.

37
Q

Q: Why is it important to flush rewrite rules after registering a taxonomy?

A

A: To ensure the correct permalinks are generated for the taxonomy.

38
Q

Q: How can you flush rewrite rules programmatically?

A

A: Use flush_rewrite_rules() in the plugin activation hook.

39
Q

Q: Why should you use meaningful names for taxonomies?

A

A: To make it clear what the taxonomy represents for both users and developers.

40
Q

Q: Why is it important to make taxonomies translatable?

A

A: To ensure internationalisation and a better experience for non-English users.