Adding a html class based on post count

If I understood this issue correctly the problem with your current code is that you are incrementing $totalPosts variable inside the while loop, so the variable gets incremented after every post thus resulting in the running order you described. To get the amount of posts returned matching the query, use $loop->found_posts (in this case) More … Read more

Wp_query with 2 meta keys and array of meta values

I think you need to do something like this: <?php $args = array( ‘post_type’ => ‘shop’, ‘post_status’ => ‘publish’, ‘posts_per_page’ => -1, ‘meta_query’ => array( ‘relation’ => ‘AND’, array( ‘key’ => ‘cu_status’, ‘value’ => array( ‘pending’, ‘processing’ ), ‘compare’ => ‘IN’, ), array( ‘key’ => ‘cu_date’, ‘value’ => array( ‘2016-01-12’, ‘2016-01-13’ ), ‘compare’ => ‘BETWEEN’, … Read more

How to provide meta_key array to wp_query?

The WP_Query() custom field (i.e. meta) query can handle arrays for field values. You just need to add the compare key to your array: $args = array( ‘numberposts’ => -1, ‘post_type’ => ‘post’, ‘meta_query’ => array ( array ( ‘key’ => ‘my_key’, ‘value’ => ‘target_value’, ‘compare’ => ‘IN’ ) ) ); $new_query = new WP_Query( … Read more

Assign custom parameter to each post in query

It’s a neat idea! The way I would tackle the problem is to create an associative array of post IDs mapped to their individual weights. Since weights are subjective – that is, the represent the value of other posts’ relationships with the post currently being displayed – it doesn’t make much sense to store these … Read more

Is it possible to reverse the order of a list of posts pulled from a loop?

Assuming you are refering to the code of this answer Taking the query from that answer $args = array( ‘category_name’ => ‘your-category-slug’, ‘posts_per_page’ => 3, ); $wpse_235685_query = new WP_Query( $args ); you would then, to reverse the order of your results, need to modify the query $posts object, like so $temp_posts = $wpse_235685_query->posts; // … Read more

Can I add generic numbering HTML classes to items as a loop runs?

You could use post_class within the loop. <?php post_class( ‘myclass-here’); ?> This will add the necessary HTML class=”” and WP defaults classes plus your new myclass-here class You could then use counters within the loop to add a unique suffix to your post class // Outside the loop initialize your counter $counter = 1; . … Read more

the_post() is printing titles in page footer

Instead of query_posts(), use WP_Query(): function shortcode_eventi() { $loop = new WP_Query(array( ‘post_type’ => ‘eventi’ )); ?> <?php if ($loop->have_posts()) : ?> <?php while ($loop->have_posts()) : $loop->the_post(); ?> <small><?php the_time(‘F jS, Y’) ?></small> <?php endwhile; ?> <?php else : ?> <h2 class=”center”>Not Found</h2> <p class=”center”><?php _e(“Sorry, but you are looking for something that isn’t here.”); … Read more