How to style archive post titles… but only those posts who have comments?

Use have_comments() function. Example: <?php if ( have_comments() ) : ?> <h2 class=”has-comments”><a href=”https://wordpress.stackexchange.com/questions/363222/<?php the_permalink(); ?>”><?php the_title(); ?></a></h2> <?php else : ?> <h2><a href=”https://wordpress.stackexchange.com/questions/363222/<?php the_permalink(); ?>”><?php the_title(); ?></a></h2> <?php endif; ?>

How to get post with associated categories and tags names instead of ids with rest api?

When I copy/pasted your code I got an error message because enf_register_categories_names_field() wasn’t defined. When I cleaned up your code and wrapped the register_rest_field() in a function called “enf_register_categories_names_field” it worked as expected. function ag_filter_post_json($response, $post, $context) { $tags = wp_get_post_tags($post->ID); $response->data[‘tag_names’] = []; foreach ($tags as $tag) { $response->data[‘tag_names’][] = $tag->name; } return $response; … Read more

How to exclude posts that already appear in the main loop, from the category loop

<?php get_header(); ?> <section class=”content latest”> <h2>Latests 20 posts</h2> <ul> <?php $the_query = new WP_Query( ‘posts_per_page=20’ ); ?> <?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?> <?php $excludeID[] = $post->ID; ?> <li> <!– post thumbnail linking to the single post page –> <?php if ( has_post_thumbnail() ) : ?> <a href=”https://wordpress.stackexchange.com/questions/366403/<?php the_permalink(); ?>” … Read more

Post Filtering by GET URL parameters

You have to filter the posts in the query arguments. Try: $mycat = $_GET[‘category’]; $arg = array( ‘type’ => ‘post’, ‘order’ => ‘ASC’, ‘category_name’ => $mycat ); Just remove the square brackets from the link, or use: $mycat[0] $mycat = $_GET[‘category’]; $arg = array( ‘type’ => ‘post’, ‘order’ => ‘ASC’, ‘category_name’ => $mycat[0] );

Count several post tags

How do I write if I would like to know how many posts there are in 10 different tags together? If you mean the combined total number of posts, i.e. the sum of the count value of each term, then: Yes, you can put the slug list in an array and loop through the items … Read more

Why this function doesn’t works without the_post?

I’m just going to quote a brief, yet comprehensive, comment on the official reference page for the_post(): Function the_post() checks whether the loop has started and then sets the current post by moving, each time, to the next post in the queue. Additionally, the “current post” here refers to the current item in WP_Query::$posts which … Read more