Skip to content
Tutorials Center
My learning

Topics

Lesson 67 of 68 ยท Practice and Review

WordPress Interview Questions

Common WordPress developer interview questions with clear answers: core concepts, hooks, queries, security, performance and block themes, plus runnable PHP demos.

A WordPress interview rarely asks you to recite the function list. Interviewers want to hear that you know how the pieces fit: how a request becomes a page, why hooks exist, what makes a query slow, and which function protects against which attack. Good answers are short, concrete and honest about trade-offs.

This page collects questions grouped by topic, each with a compact answer you can say out loud in about thirty seconds. Open an answer only after you have tried to formulate your own. Three questions come with small runnable PHP demos. As everywhere in this course, real WordPress cannot run on this page, so the demos are plain-PHP stand-ins that show the idea, not core's code.

flowchart TD
    Q["Interview question"] --> A["1. Name the concept"]
    A --> B["2. Explain why it exists"]
    B --> C["3. Give a small example"]
    C --> D["4. Mention a pitfall"]

A four-step shape for almost any technical answer: say what it is, why it exists, show one example, and name the classic mistake.

Core concepts

What happens when a visitor requests a page?

The web server hands the request to index.php, which loads WordPress. Core loads the configuration, the active plugins and the theme, then runs the init action. It parses the URL against the rewrite rules into query variables and runs the main query. It then chooses a template using the template hierarchy, and the template prints the page through the loop. See How WordPress Handles a Request.

What is the difference between a post, a page and a custom post type?

All three are rows in the wp_posts table, told apart by the post_type column. Posts are dated, listed in archives and can use categories and tags. Pages are hierarchical, undated and do not have categories by default. A custom post type is one you register yourself, for example book, with its own labels, supported features and archive. See The WordPress Database Schema and Custom Post Types.

When do you use a plugin and when do you use a theme?

Put presentation in the theme and functionality in a plugin. If a feature (a custom post type, a shortcode, a tracking script) should survive a redesign, it belongs in a plugin. A feature in functions.php disappears the day the theme is switched.

What is the difference between post meta and options?

Post meta stores key-value data attached to one post, in wp_postmeta. Options store site-wide settings in wp_options. Choose by scope: a book's ISBN is post meta, the site's API key is an option. Options flagged as autoload are loaded on every request, so large values do not belong there.

What is the difference between wordpress.org and wordpress.com?

WordPress.org offers the open-source software you download and host yourself, with full control over themes, plugins and code. WordPress.com is a hosting service built on that software, where the available features depend on the plan.

Hooks

What is the difference between an action and a filter?

An action lets you run code at a point in time: "when a post is saved, do this". It returns nothing that matters. A filter lets you change a value: it receives data, and must return it, modified or not. See Actions and Filters.

What does the priority do, and what is the default?

The priority orders callbacks on the same hook. Lower numbers run first, and the default is 10. Callbacks with the same priority run in the order they were registered. Use a distinct priority whenever order matters. See Priorities, Order and Removing Hooks.

Why did my remove_action() call do nothing?

Usually one of three reasons: the priority does not match the one used when registering, the callback is not the same one (a different object instance, or a closure you cannot reference), or the removal ran before the callback was added or after the hook already fired.

What goes wrong when a filter callback forgets to return?

The value becomes null for every later callback and for the code that called apply_filters(). The demo below shows it.

PHP A filter that forgets to return

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with fgets(STDIN)), it gets the next line from this box.

How do you make your own plugin extensible?

Fire your own hooks with do_action() and apply_filters() at the points where others may want to customise behavior, give them a unique prefix such as myplugin_, and document the arguments. See Creating Your Own Hooks.

Queries and the loop

What is the difference between WP_Query, get_posts() and query_posts()?

WP_Query is the class that runs a query and gives you the full loop API plus found_posts and max_num_pages. get_posts() is a convenience wrapper that returns a plain array of post objects, skips pagination counting and suppresses some filters. query_posts() replaces the main query after it already ran, wasting a database query and breaking pagination: do not use it. See WP_Query in Depth.

How do you change what the main query shows on an archive page?

Hook pre_get_posts and change the query object, but only when it is the right query: check ! is_admin() and $query->is_main_query(), and any conditional tags such as is_post_type_archive(). See The Main Query and pre_get_posts.

Why call wp_reset_postdata() after a secondary loop?

A loop over your own WP_Query changes the global $post. Resetting restores the global to the post of the main query, so template tags used afterwards, in a sidebar or footer, refer to the page being viewed. See The Loop.

Why can meta queries be slow?

Post meta is stored as one row per key and value in wp_postmeta, and values are text. Every meta_query clause adds a join or sub-condition, and comparisons on numbers or dates need casting, which defeats index use. Filter by taxonomy where you can, keep the number of clauses small, and cache expensive results. See Meta Queries and Taxonomy Queries.

Security

What is a nonce, and what does it protect against?

A nonce ("number used once", though WordPress nonces are valid for a time window) is a token tied to a user, an action and a time tick. It helps protect against cross-site request forgery: a request that carries a valid nonce was probably produced by a page your site rendered for that user. It does not prove the user may perform the action, so a capability check is still required. See Forms and Nonces.

What is the difference between sanitizing, validating and escaping?

Validating asks "is this acceptable?" and rejects what is not. Sanitizing cleans a value into an acceptable form when it arrives, for example sanitize_text_field() or absint(). Escaping prepares a value for output in a specific context, for example esc_html(), esc_attr() or esc_url(). Sanitize early, escape late. See Sanitizing and Validating Input and Escaping Output.

Why does the escaping function depend on context?

Each output context has different dangerous characters. In an HTML text node, < matters. In a quoted attribute, the quote matters. In a URL, the scheme matters, because javascript: runs code. The demo shows one payload in three contexts.

PHP Escape for the context you print into

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with fgets(STDIN)), it gets the next line from this box.

How do you protect against SQL injection?

Never concatenate variables into SQL. Use the API (WP_Query, get_posts(), update_post_meta()) when it covers your case. When you write SQL with $wpdb, pass every variable through $wpdb->prepare() with %s, %d and %f placeholders. See $wpdb and Custom Tables.

How would you check that the user may do something?

Use current_user_can() with the most specific capability, for example current_user_can( 'edit_post', $post_id ), before changing data, on every request that does it. Hiding a button is not security. See Users, Roles and Capabilities.

Performance

What is the N+1 query problem, and how do you avoid it in WordPress?

Running one query for a list and then one more per item. In WordPress it appears when code reads data row by row inside a loop. Core's WP_Query primes the post meta and term caches for the posts it fetched, so the standard functions are usually safe. Custom SQL or direct lookups of unrelated tables are where N+1 returns. Batch the lookups. The demo counts queries both ways.

PHP Counting queries: N+1 versus one batch

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with fgets(STDIN)), it gets the next line from this box.

What can you do to speed up a slow WordPress site?

Measure first (a profiler such as Query Monitor, and the browser's performance tools). Then look at the usual suspects: a full-page cache, a persistent object cache such as Redis, heavy autoloaded options, slow queries, unoptimized images, and scripts and styles loaded on pages that do not need them. See Caching and WP-Cron and Performance Optimization.

What are transients?

Transients are cached values with an expiry time, stored with set_transient() and read with get_transient(). By default they live in the options table. With a persistent object cache they live in that cache instead. Always code for a miss: a transient can disappear at any moment. See The Options API and Transients.

How does WP-Cron work, and what is its limitation?

WP-Cron is not a real scheduler: it checks for due events when someone loads a page. On a low-traffic site tasks run late, and on a busy site the check adds overhead. For reliable timing, disable the page-load trigger and call wp-cron.php from a real system cron job.

Themes and blocks

What is the difference between a classic theme and a block theme?

A classic theme uses PHP template files and the Customizer. A block theme uses HTML templates built from blocks, a theme.json file for design settings, and the Site Editor, so users can edit templates visually. Both follow the same template hierarchy logic. See Block Themes: The Big Picture.

What does theme.json do?

It declares the editor's settings (palette, font sizes, spacing, layout widths) and the global and per-block styles. WordPress turns those into CSS custom properties and block styles, giving the theme and the editor one source of design values. See theme.json.

How do you load CSS and JavaScript correctly?

Register and enqueue them on the wp_enqueue_scripts hook with wp_enqueue_style() and wp_enqueue_script(), declare dependencies, and give a version for cache busting. Never print <link> or <script> tags by hand in templates. See Enqueuing Styles and Scripts.

What is a child theme for?

It lets you customise a parent theme without editing it, so parent updates do not erase your changes. The child can override templates and add code. See Child Themes.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. A colleague's filter on the_content runs fine but the post body is empty. What is the most likely cause?

    A filter's return value replaces the content. A callback without a return statement returns null, which empties the output.
  2. 2. What is the right way to change the order of posts on the blog archive?

    pre_get_posts changes the main query before it runs. query_posts() replaces it after the fact and breaks pagination, and editing core files is never acceptable.
  3. 3. Which statement about nonces is correct?

    A nonce shows that the request likely came from a page your site generated for that user. Whether the user may perform the action is decided by a capability check.
  4. 4. Why is a loop that calls a meta lookup once per post a problem?

    That is the N+1 pattern: one query for the list plus one for each item. Batching the lookup keeps the number of queries constant.

Summary

  • Answer in four steps: what it is, why it exists, a small example, a classic pitfall.
  • Actions run code at a moment; filters change a value and must return it.
  • Use pre_get_posts for the main query, never query_posts(); reset post data after secondary loops.
  • Sanitize early, escape late and in the right context, bind SQL values, check capabilities, and use nonces against CSRF only.
  • Measure before optimizing: caching, autoload, query count and asset loading are the first places to look.
  • Block themes bring HTML templates and theme.json, but follow the same hierarchy logic as classic themes.

Last, keep a WordPress Cheat Sheet close at hand.