Show all products on one page with WooCommerce

Just add the conditional check to your functions.php file: if( isset( $_GET[‘showall’] ) ){ add_filter( ‘loop_shop_per_page’, create_function( ‘$cols’, ‘return -1;’ ) ); } else { add_filter( ‘loop_shop_per_page’, create_function( ‘$cols’, ‘return 12;’ ) ); }

Count the number of images uploded on the website

There’s a handy built-in function, namely wp_count_attachments(). We can filter out images with wp_count_attachments( $mime_type=”image” ) that returns an object like: stdClass Object ( [image/gif] => 9 [image/jpeg] => 121 [image/png] => 20 [image/x-icon] => 6 [trash] => 0 ) So we can use the one-liner: $count = array_sum( (array) wp_count_attachments( $mime_type=”image” ) ); for … Read more

How to display post from current Taxonomy in archive page?

You will need to grab the queried object for the page and fill in your taxonomy information dynamically. if (is_tax() || is_category() || is_tag() ){ $qobj = get_queried_object(); // var_dump($qobj); // debugging only // concatenate the query $args = array( ‘posts_per_page’ => 1, ‘orderby’ => ‘rand’, ‘tax_query’ => array( array( ‘taxonomy’ => $qobj->taxonomy, ‘field’ => … 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

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