[…] WordPress, here are two examples where I’ve found declaring variables, even if they are only going to be used once, to improve the code. An Example with WP_Query A lot has already been said, written, and shared about WP_Query and that particular class isn’t even the point of this post, save for the fact […]
Search: “wp_query” (Page 5 of 29)
We found 145 results for your search.
[…] LIKE operation rather than an IN operation or = operation. Some of the things that are important to know before reading the rest of this article include: WP_Query The posts_where hook The pre_get_posts hook Regular expressions with preg_replace WordPress helper functions, namely esc_sql. Ultimately, we’re going to need to use two hooks with two […]
[…] easy enough, doesn’t it? Finding Posts Without Meta Data For the most part, it is. But when working on this particular plugin I found this familiarity with WP_Query played a huge part in being able to get some of the functionality done and I thought it might be worth sharing how both the meta data […]
[…] the page * @since 1.0 */ function example_get_permalink_by_slug( $slug, $post_type = ” ) { // Initialize the permalink value $permalink = null; // Build the arguments for WP_Query $args = array( ‘name’ => $slug, ‘max_num_posts’ => 1 ); // If the optional argument is set, add it to the arguments array if( ” != […]
Have you ever had the, ahem, pleasure of customizing the WordPress query? One of the most useful things in debugging is displaying the last WordPress query.
Let’s say you’re working with taxonomies and/or post types and you’re passing custom parameters around. And then, you want to setup some debugging to see exactly what’s hitting the database.
This is helpful for a variety of reasons if for no other reason than to see what is running against the database. It gives you insight on what you’re requesting and thus what you’re presenting to the user.
Anyway, writing code to do this is easy.
