Exclude drafts in all() view of edit.php

The show_in_admin_all_list parameter in the register_post_status() function, determines if a given post status is included in the All post table view. Probably the shortest version is: add_action( ‘init’, function() use ( &$wp_post_statuses ) { $wp_post_statuses[‘draft’]->show_in_admin_all_list = false; }, 1 ); but let’s avoid modifying the globals directly like this and override the default draft status … Read more

WP Query orderby meta key natural sort?

No, not as a straight WP_Query. This is because of several factors, with the main one being that mySQL doesn’t natively have a natural sort for alphanumeric columns. WordPress does support a “meta_value_num” for the orderby parameter, which causes it to cast the values to numeric to perform the sort, and this works when you’re … Read more

Better way to get tag stats?

I addressed a similar problem not long ago – it’s all in the memory: $post_ids = get_posts( array( ‘posts_per_page’ => -1, ‘post_status’ => ‘publish’, ‘fields’ => ‘ids’, // Just grab IDs instead of pulling 1000’s of objects into memory ) ); update_object_term_cache( $post_ids, ‘post’ ); // Cache all the post terms in one query, memory … Read more

What exactly does the ‘s’ parameter search for in WP queries?

As usual it’s most reliable to dump the resulting SQL query and see: SELECT wp_posts.ID FROM wp_posts WHERE 1=1 AND (((wp_posts.post_title LIKE ‘%keyword%’) OR (wp_posts.post_content LIKE ‘%keyword%’))) AND wp_posts.post_type=”post” AND ((wp_posts.post_status=”publish”)) ORDER BY wp_posts.post_date DESC LIMIT 0,5 The only two things native search is considering are title and content.

WP Query to get all posts (including in draft/pending review)

You can add post_status to your query, the string ‘any’ will return all posts no matter the status, or you can use an array to just grab those you want. $args = array( ‘post_type’ => ‘post’, ‘orderby’ => ‘title’, ‘order’ => ‘ASC’, ‘post_status’ => ‘any’, ‘posts_per_page’ => 10, ); http://codex.wordpress.org/Class_Reference/WP_Query#Status_Parameters

Tax_query terms ID’s using variable

It looks like you are making an array with a single string inside. Check if making $tax into an array before passing it will work: $tax = array( 19, 18, 214, 226, 20 ); $query_args = array ( ‘post_type’ => ‘works’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘materials’, ‘field’ => ‘term_id’, ‘terms’ => $tax, ) … Read more

tech