WP Ref

Category: Development

  • How to Use get_posts to Retrieve the Posts You Need

    I can’t think of many functions that I use more often than get_posts. As a wrapper for WP_Query, get_posts provides a convenient way to retrieve just the posts you need. In this guide, I’m going to dive into all the different options you can use to retrieve the posts you need. In this article: Basic…

  • Using Anonymous Functions for Testing Hooks

    There are times when you just want to try some code for a hook, but can’t be bother to write a separate function or class method. This can certainly be the case for myself when I’m working with a class with many methods, or a long file. Trying It Out Let’s say we want to…

  • Using var_export to Debug and Prettify Dumps of Anything

    When developing for WordPress (and anything in PHP in-fact), it can be incredibly useful to be able to dump values. Yes, there’s a function for that called var_dump, which is great… if you’re not dealing with anything complex. As soon as you output anything more complex such any type of array, object, or class instance,…

  • Plugin Headers

    Every WordPress plugin contains a plugin header. The plugin header is a multi-line PHP comment containing various details about the plugin. WordPress detects if a file represents a plugin if it contains a plugin header. The details in the header are used on the Plugins dashboard page. Here is the simplest example of a plugin…

  • Hooks — The Ultimate Guide

    Hooks are the bread and butter behind each WordPress website. A hook is an execution point where WordPress checks to see if there are any callbacks to run. There are two types of hooks: an action, and a filter. Use Cases There are many use cases for hooks. Hooks are convenient because you don’t need…

  • Creating Local WordPress Installations for Development Using Local

    When developing and extending WordPress, it’s important to have a great development environment from the get-go. I’ve tried all sorts of software solutions from WAMPP, to MAMPP, to installing a LAMP stack manually. By far the easiest development environment I’ve used thus far is an application called Local. Local is an application that runs on…