Display name of taxonomy once

Not the best, but works well for me: (you can use this instead of what’s in the question) $postcount = 0; //global $wp_query; // Uncomment if necessary. // Group the posts by category. $groups = []; foreach ( $wp_query->posts as $i => $p ) { $terms = wp_get_post_terms( $p->ID, ‘show_category’ ); foreach ( $terms as … Read more

Loop in elementor custom widget not working

I would recommend switching to a standard post loop: $args = [ ‘posts_per_page’ => 12, ‘category_name’ => ‘featured’, ‘orderby’ => ‘post_date’, ‘order’ => ‘ASC’, ]; $query = new \WP_Query($args); if ( $query->have_posts() ) { while ( $query->have_posts() ) { $query->the_post(); ….. } \wp_reset_postdata(); } Note that I: switched to modern PHP array syntax of [] … Read more

Show articles in Pair

I would a bit more detail (or your starting code ) to see where you’re putting this or how you want to use it but from what I see you need to add a counter to your iteration and then use a modulo operator: a sample query would look like this though: $winnners_query = new … Read more

Should I reset $wp_query?

The query is right and its working. But should I reset something? Yes! Should I reset them both or just one of them, or is it fine like above? Neither! Your WP_Query object is self contained in $query, so there’s no reason to touch the $wp_query global variable, why would you? $wp_query represents the main … Read more

display post format text in loop

get_post_format() returns the post format slug for either the current post, when used inside a loop, or a given post, when a WP_Post object or an integer post ID is passed to it as a parameter. So, if you’re using the function in a posts loop, then you can use it like this, while ( … Read more

Issue with custom loop in Archive page

The problem is you aren’t saving your custom query’s results. To do it your way, you would need to save the query’s results to a variable, like so: $myposts = query_posts( $archive_args ); if ( $myposts->have_posts() ) : while ($myposts->have_posts()) : $myposts->the_post(); However, that’s not the most efficient way. WP runs the default query in … Read more

How to get a count of all posts in foreach loop and split into fourths

I had a similar problem couple years ago. Here’s a gist I’ve published, which shows the basic idea how I solved the problem,https://gist.github.com/koskinenaa/4d8461116885c0e64d5ca167ae53434d Applying the gist to your situation I think the solution could be something like this. I didn’t test this so it might require some tweaking, but it should at least point you … Read more