In the previous post, I shared how I used to use the following rule of them when passing variables in WordPress (and other programming languages, really):
“Only if I need to use this value more than once, then I will store it in a variable.”
And though I still think it’s a fair rule to follow, there are exceptions.
The more time I’ve spent writing code and having to maintain codebases from both myself and others, the more I’ve appreciated having variables defined – even if they are used only once – that hold more complex information for the sake of readability, clarity, and maintainability.
In the last post, I looked at an example as it relates to
WP_Query since it’s one of the more powerful aspects of the WordPress API, but I’ve found that the same is true in simpler complex such as loops.