Count Number of Posts in Taxonomy Term in Last 24 Hours

You can create a custom WP_Query and count its result. $wp_query = new WP_Query([ ‘tax_query’ => [ [ ‘taxonomy’ => ‘news’, ‘terms’ => $term_name, ‘fields’ => ‘name’ ] ], ‘date_query’ => [ [ ‘after’ => ’24 hours ago’ ] ] ]); $number_of_posts = $wp_query->found_posts; Edit I removed posts_per_page argument, as @birgire suggests, that found_posts offers … Read more

Display Notification Bar on Header on Certain Post Count

A simple way to achieve this would be to do something like the following; <?php $user_id = get_current_user_id(); $post_count = count_user_posts($user_id); if ($post_count >= 50 && $post_count < 100) { // Congratulations you have submitted 50 posts! } elseif ($post_count >= 100) { // etc etc… } else { // do something else, or nothing. … Read more

How to count posts with specific arguments

The easiest way to optimize this query would be to add ‘fields’ => ‘ids’ to the arguments. This way only ids of posts will be retrieved from DB (and usually that’s a big change). $args = [ ‘numberposts’ => -1, ‘post_type’ => ‘jobs’, ‘s’ => ‘developer’, ‘tax_query’ => [‘taxonomy’ => ‘IT’, ‘field’ => ‘slug’], ‘fields’ … Read more

Counting posts with argument without retrieving the posts

Here’s one thing you could do. Create a WP_Query object but only include ids: $args = array( ‘posts_per_page’ => -1, ‘post_type’ => ‘books’, ‘s’ => $s, ‘fields’ => ‘ids’, ); $query = new WP_Query( $args ); $post_counts = $query->post_count; wp_reset_postdata(); By using fields => ids you’re only returning the IDs. Also, WP_Query already does a … Read more

How do I display an image before the first post of the loop when I’m using get_template_part?

The variable $count is accessible in the scope of the current function only. So whatever happens inside get_template_part() cannot know that variable. You could use a global variable, which is accessible everywhere as $GLOBALS[‘count’]. But then you risk collisions with plugins and maybe other code. I recommend a helper function for the functions.php: /** * … Read more

Getting comment count per post not working

Try this: <?php $popular = new WP_Query(‘orderby=comment_count&posts_per_page=5’); ?> <?php while ($popular->have_posts()) : $popular->the_post(); ?> <li><a href=”https://wordpress.stackexchange.com/questions/108038/<?php the_permalink(); ?>”><?php the_title(); ?></a> has <?php comments_number( ‘no responses’, ‘one response’, ‘% responses’ ); ?>.</li> <?php endwhile; ?> From the codex.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)