why does not my wp_query work?

There are several issues here, starting with the first part: <?php $postnumcat = new wp_query (array( ‘post_status’ => ‘publish’, ‘post_type’ => ‘post’, ‘cat’ => ‘-1’, ‘posts_per_page’ => ‘-1′, )); Firstly, wp_query is misspelt, it’s WP_Query Some general notes too: Setting posts_per_page to -1 is bad for performance. Even if you don’t expect there to be … Read more

wp_query sort with meta_value_num is not working

From your comment: it worked without the array( ‘key’ => ‘picture_url’, ‘value’ => ‘none’, ‘compare’ => ‘!=’ ) but I need to include it in the query… is it possible? Yes, using named sub-meta queries like so: $q_args = [ // … other args here … ‘meta_query’ => [ ‘picture_url’ => [ ‘key’ => ‘picture_url’, … Read more

Custom Taxonomy Not Showing in Front-End When Outputting a Custom Post Type with WP_Query()

From your explanation above I understood that you want to show custom taxonomy you have registered for that post type. the_category(); fetches the default category that comes with the default post. For rendering custom taxonomy you need to add something like this: $terms = get_the_terms( $post->ID , ‘your custom taxonomy slug’ ); foreach ( $terms … Read more

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

How I can use order by of the custom post title?

You can use the order and orderby param in WP_Query argument like below: $args = array( ‘post_type’ => ‘case’, ‘post_status’ => ‘publish’, ‘meta_key’ => ‘client’, ‘posts_per_page’ => 9, ‘orderby’ => ‘title’, ‘order’ => ‘ASC’, ); $query = new WP_Query( $args ); It will list out your posts by title. For more information check official WordPress … 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