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;’ ) ); }

Archive Listings Filtered by Date Values in a Custom Field/Post Meta?

As with many things in WordPress there are several ways to do what you want. I’m going to explain one of them. Remove the ‘year’, ‘monthnum’ and ‘day’ Query Variables You can modify the parameters to the query WordPress uses on the archive URLs inside the ‘pre_get_posts’ hook. Those parameters are captured as an associative … Read more

Custom Taxonomy with Custom Post Type Finds No Posts

I don’t know how or why, but this code below solved by issue. Seems to me like I shouldn’t need it, but apparently I do. add_filter(‘pre_get_posts’, array(&$this, ‘modify_pre_query_request’)); public function modify_pre_query_request($query){ if ($query->is_main_query()){ if ($query->is_tax){ $post_type = get_query_var(‘post_type’); if (!$post_type){ $post_type = array( ‘post’, ‘YOUR POST TYPE’ ); $query->set(‘post_type’, $post_type); } } } } Keep … Read more

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

WP_Query in functions.php

Simple, you’re addressing $post out of context. When you’re running a standard WordPress loop, WP will load a global $post variable with the results of the current query. This includes the ID, title, content, post meta, etc. The loop functions will reference this global variable to actually give you data. Take the regular function get_the_ID() … Read more

Filtering a WP_Query meta_query by numeric values isn’t working

Try an array of arrays in your meta query. $args = Array( ‘post_type’ => ‘event’, ‘posts_per_page’ => -1, ‘meta_key’ => ‘event_date’, ‘orderby’ => ‘meta_value_num’, ‘order’ => ‘ASC’, ‘meta_query’ => array( array( ‘key’ => ‘event_date’, ‘compare’ => ‘>=’, ‘value’ => intval(strtotime(date(‘Y-m-d’))), ‘type’ => ‘numeric’ ) ), ); $query = new WP_Query( $args );

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

tech