Using get_posts vs. WP_Query

This is directly related to, and a consequence of WordPress.com VIP At VIP, we deal with sites that range in the hundreds of millions of page views per week. As a result, situations that can slow down your site are much more noticeable at that scale than on a small shared host, but this still … Read more

How to order by post_status?

You can use ‘posts_orderby’ filter to change the SQL performed. Note that: using get_posts() you need to set ‘suppress_filters’ argument of false for the filter to be performed if you don’t explicitly set ‘post_status’ you’ll get only published posts (so no much to order) Code sample: $filter = function() { return ‘post_status ASC’; }; add_filter(‘posts_orderby’, … Read more

WordPress get_posts function, 1300 lines long

Yes. To give you some historical perspective WordPress core: is relatively old code base, code volume tends to grow over time; has extreme commitment to backwards compatibility, as result it’s extremely rare for code to be removed from core; is written in essentially obsolete dialect of PHP version 5.2 (which it remains compatible with), which … Read more

Multiple custom fields for ‘orderby’ in ‘WP_Query’

meta_query and orderby are seperate parameters, you just put them together in an array. You will have to do one then the other. e.g. <?php $args = array( ‘post_type’ => ‘property’, ‘meta_query’ => array( array( ‘relation’ => ‘AND’, ‘city_clause’ => array( ‘key’ => ‘city’, ‘compare’ => ‘EXISTS’, ), ‘street_clause’ => array( ‘key’ => ‘street_name’, ‘compare’ … Read more

WP_QUERY Get posts by category and similar name (Like)

Revisited and simplified answer: You can try: $args = [ ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’, ‘category_name’ => ‘projects’, ‘_name__like’ => ‘proj*’ // <– our new input argument! ]; $my_query = new WP_Query( $args ); where we’ve created the _name__like input argument. It supports wildcard *, for example: ‘_name__like’ => ‘a*b*’ Note that draft posts … Read more

How to list some posts first in the loop based on post id

If you need to: page the query retain 12 posts per page instead of “sticking” the desired posts on top of the required 12 only need to show those posts on the first page you can try the following $ids_args = [ ‘post_type’ => ‘products’ ‘posts_per_page’ => -1, ‘orderby’ => ‘meta_value_num’, ‘meta_key’ => ‘_price’, ‘order’ … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)