Query about wp_query

Basically meta_query parameter of WP_Query allows you to search WordPress posts / pages / custom post types by their meta data and sort the result. In this post I assume that you already have basic knowledge how to work with WP_Query class in WordPress. Before I begin, I want to show you some very simple … Read more

Query with meta_query and tax_query together not working properly

Tax query is formed wrong. It also array of arrays(queries) get_posts([ ‘meta_query’ => [ [ ‘key’ => ‘country’, ‘value’ => ‘Japan’, ‘compare’ => ‘LIKE’ ] ], ‘tax_query’ => [ [ ‘taxonomy’ => ‘category’, ‘field’ => ‘slug’, ‘terms’ => [‘kids’] ] ] ]); the array should look like this: Array ( [meta_query] => Array ( [relation] … Read more

Make meta query treat meta_value as 1 or 0

If I understand it correctly.. What you’re looking for can be achieved using the CASE statement in MySQL, where you would use the following in the ORDER BY clause: # group the quantity meta into two groups CASE # group one – all quantities that are 1 or more; we flag them as “1” WHEN … Read more

WordPress posts for multiple years

You should use a date range instead by filtering posts_where: function wpse_43397_where($where=””){ $where .= ” AND post_date >= ‘2008-01-01’ AND post_date < ‘2010-12-31′”; return $where; } add_filter(‘posts_where’, ‘wpse_43397_where’); $my_query = new WP_Query($args); remove_filter(‘posts_where’, ‘wpse_43397_where’);

Category ‘pad_counts’ & ‘parent’ conflict

This is potentially a bug* – but it doesn’t seem like it is the same one you have linked to. The problem lies in the get_terms function. Specifically here: http://core.trac.wordpress.org/browser/trunk/wp-includes/taxonomy.php#L1397 The array of terms (which when parent=0, are are just the top level terms) gets passed to _pad_term_counts which says: Add count of children to … Read more

Does wp track views for posts?

WordPress does not maintain post view count by default. But you may find the following post helpful. Does wordpress have a post hit counter? You may also have a look on the WP-PostViews plugin. Many thanks.

Taxonomy order exception for specific term

Here is the example of get_terms in the Codex: $terms = get_terms(“my_taxonomy”); $count = count($terms); if ( $count > 0 ){ echo “<ul>”; foreach ( $terms as $term ) { echo “<li>” . $term->name . “</li>”; } echo “</ul>”; } Lets say there was an ‘other’ term in my_taxonomy. To place it at the end … Read more

WordPress | Date not always appear [duplicate]

Use get_the_date() instead, here’s note from the_date() codex page regarding the issue: When there are multiple posts on a page published under the SAME DAY, the_date() only displays the date for the first post (that is, the first instance of the_date()). To repeat the date for posts published under the same day, you should use … Read more