wpdb::prepare was called incorrectly

It’s always advised to use $wpdb->prepare when you are taking input from user. This will help in protecting queries against SQL Injection. For more details, check the Codex When you use $wpdb->prepare, you must pass the variables to the query. In your case, you can skip using $wpdb->prepare as you are using a hard coded … Read more

Optimize Multiple Taxonomy Term MySQL Query?

While this is really a MySQL question it does help to understand the WordPress SQL schema and also I love trying to optimize SQL queries so rather than send you off to StackOverflow I’ll try to answer you here. You may still want to post it over there to get some other opinions. And while … Read more

How to search display_name column when using WP_User_Query

You can try this: /** * Add support for the “display_name” search column in WP_User_Query * * @see http://wordpress.stackexchange.com/a/166369/26350 */ add_filter( ‘user_search_columns’, function( $search_columns ) { $search_columns[] = ‘display_name’; return $search_columns; } ); where we use the user_search_columns filter to modify the available search columns. So what fields can we use with this filter? Here’s … Read more

Query WooCommerce orders where meta data does not exist

The meta_query argument (that you can use in a WP_Query) is not enabled by default when using a WC_Order_Query through wc_get_orders() WooCommerce function. But for you can use the undocumented Custom Field Parameters (just like in a WP_Query): meta_key meta_value meta_value_num meta_compare So in your case you can use the following instead: $orders = wc_get_orders( … Read more

Get wp_get_attachment_url outside of loop

if the result you’re looking for is a printout of the URL, like in your example, then this should work: $page_id = get_queried_object_id(); if ( has_post_thumbnail( $page_id ) ) : $image_array = wp_get_attachment_image_src( get_post_thumbnail_id( $page_id ), ‘optional-size’ ); $image = $image_array[0]; else : $image = get_template_directory_uri() . ‘/images/default-background.jpg’; endif; echo $image;

wordpress query – orderby child post date

You should be able to do this with the get_children function (see the codex), $ticket_id = 34; // assume you want to retried the replies of ticket post id=34 $args = array( ‘post_type’ => ‘support_tickets’, ‘numberposts’ => -1, ‘post_parent’ => $ticket_id, ‘orderby’ => ‘date’, ‘order’ => ‘DESC’ ); $replies = get_children( $args ); Assuming that … Read more

WP_Site_Query vs. WP_Network_Query in WordPress 4.6

When you set WordPress to multisite, in an “out of box” fashion, you create a single network of sites. Let’s, say, a network of food blogs. With plugins like WP Multi Network you can set up multiple networks. You could split that food blogs network into several networks: mediterranean food blogs, brazilian food blogs, thai … Read more