WordPress Developer 3 — Questions and Answers
Question 1: Which function registers a new custom post type in WordPress?
- register_post_type() (Correct answer)
- add_post_type()
- create_post_type()
- new_post_type()
Correct answer: register_post_type()
register_post_type() is the official WordPress function for creating custom post types, called on the 'init' hook.
Question 2: In WordPress REST API, what HTTP method is used to partially update an existing resource?
- POST
- PUT
- PATCH (Correct answer)
- DELETE
Correct answer: PATCH
PATCH is used to partially update a resource, while PUT replaces the entire resource.
Question 3: What is the difference between wp_die() and die() in WordPress?
- wp_die() outputs a formatted HTML page with proper headers and WordPress styling (Correct answer)
- wp_die() only works in admin areas while die() works everywhere
- wp_die() sends an email notification before stopping execution
- There is no functional difference between the two
Correct answer: wp_die() outputs a formatted HTML page with proper headers and WordPress styling
wp_die() provides a properly formatted error page consistent with WordPress UI, while die() just halts PHP execution.
Question 4: Which WordPress function should you use to safely output user-submitted data in HTML attributes?
- esc_attr() (Correct answer)
- esc_html()
- sanitize_text_field()
- wp_kses()
Correct answer: esc_attr()
esc_attr() escapes data for use in HTML attributes, encoding quotes and special characters appropriately.
Question 5: What argument in WP_Query lets you query posts from multiple custom taxonomies simultaneously?
- tax_query (Correct answer)
- taxonomy
- term_query
- meta_query
Correct answer: tax_query
tax_query accepts an array of taxonomy parameters and supports 'relation' to combine multiple taxonomy queries.
Question 6: Which WordPress constant defines the path to the wp-content directory?
- WP_CONTENT_DIR (Correct answer)
- CONTENT_DIR
- WP_CONTENT_PATH
- ABSPATH
Correct answer: WP_CONTENT_DIR
WP_CONTENT_DIR holds the absolute filesystem path to wp-content, while WP_CONTENT_URL holds the URL.
Question 7: What is the correct hook to use when adding custom columns to the admin post list table?
- manage_{post_type}_posts_columns (Correct answer)
- add_post_columns
- admin_post_columns
- manage_post_list_columns
Correct answer: manage_{post_type}_posts_columns
The manage_{post_type}_posts_columns filter lets you add or remove columns from the admin post list for a specific post type.
Which function registers a new custom post type in WordPress?