WP_Query Excluding pages with Order is 0

You can define custom where like this if your table is wp_posts function _20170112( $where ){ $where = $where . ‘ AND wp_posts.menu_order > 0 ‘; return $where; } And sandwich your query with this: $args = array( ‘post_type’ => ‘page’, ‘post_status’ => ‘publish’, ‘meta_key’ => ’tile-home’, ‘meta_value’ => 1, ‘orderby’ => ‘menu_order’, ‘order’ => … Read more

Category attribute not working in custom shortcode

So I see two things that could contribute to the problem: I really doubt you’ll need to esc_attr for the query. This is a tricky one, but tax_query needs to be an array of arrays Based on this, I believe this will work better for you: $tax_query = array( ‘taxonomy’ => ‘resources_categories’, ‘field’ => ‘slug’, … Read more

How to access a query twice in different template files?

You could cache the results for that page load. It should hit it in header.php, cache the object, and in index.php you can check availability. Header $custom_query = new WP_Query( $args ); if( $custom_query->have_posts() ) { // Cache Query before loop wp_cache_add( ‘custom_query’, $custom_query ); while( $custom_query->have_posts() ) { $custom_query->the_post(); // Do some stuff, like … Read more

WP_Query on custom field and order results

Change your code with this and might help you with what you are looking for. The issue here is that we cannot include key, order and orderby in meta_query. But if you want to order you result posts based on key than you can pass the query arguments as below: $custom_query_args = array( ‘post_type’ => … Read more

Can I count matches without doing a query?

The non perfect solution is to just minimize the amount of information carried by the query, and the side effects. This can be done by requesting only the post IDs and not populating any caches. Your query should be something like $query = new WP_Query(array( … ‘fields’ => ‘ids’, ‘cache_results’ => false, ‘update_post_meta_cache’ => false, … Read more

Query total number of posts

How could I get the static total number of posts which wouldn’t change irrespective of what the user filters? You may be looking for wp_count_posts(): Codex: WP COUNT POSTS Example getting number of all published posts: function get_all_them_posts(){ $count_posts = wp_count_posts(); $published_posts = $count_posts->publish; return $published_posts; } In template: <?php echo get_all_them_posts(); ?> For Custom … Read more