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

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

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