manage_posts_custom_column, showing serial number using increment in loop

This code will add an Index value to each post which is determined by $wp_query->current_post, the number of posts per page, and the current page being viewed. add_filter( ‘manage_posts_columns’, ‘wpse240648_manage_posts_columns_index’); function wpse240648_manage_posts_columns_index($columns) { $columns[‘index’] = __( ‘Index’, ‘your-text-domain’ ); return $columns; } add_action( ‘manage_posts_custom_column’, ‘wpse240648_manage_posts_custom_column_index’, 10, 3 ); function wpse240648_manage_posts_custom_column_index( $column, $post_id ) { if … Read more

Hide post if matches current month and year

Initialize an array before the first loop: $exclude = array(); Then add the ID of each post within the first loop to that array: while ($query->have_posts()) { $query->the_post(); $exclude[] = get_the_ID(); // etc… Then use that array to exclude those IDs via post__not_in in the second query: $args = array( ‘post_type’ => ‘page’, ‘post__not_in’ => … Read more

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

Loop through all product posts?

Take a look at WordPress codex for WP_Query for more information. You’ll see there are different parameters for WP_Query, you just need to add the posts_per_page parameter with the value set to -1 to show all posts. $products_IDs = new WP_Query( array( ‘post_type’ => ‘product’, ‘posts_per_page’ => -1, )); while ($products_IDs->have_posts() ) : $products_IDs->the_post(); // … 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