Count views without get_post_meta

If you provided full code, issue is probably in this line: $wpdb->prepare(“INSERT INTO ‘myprefix_posts_views’ (postid, ip, device) VALUES (%d, %s, %s) ON DUPLICATE KEY UPDATE create_at=VALUES(create_at)”, $postID, $_SERVER[‘REMOTE_ADDR’], $_SERVER[‘HTTP_USER_AGENT’]); Because into column postid you are trying to put variable $postID, when you didn’t declare it anywhere. This column is NOT NULL, so probably you have … Read more

Comment count next to post title?

On most cases you should be able to use the_title filter to modify the title string. Use get_comments_number() to get the comments count for the post – of given ID or the current one. For example, add_filter( ‘the_title’, ‘wpse_427277_the_title’, 10, 2 ); function wpse_427277_the_title( string $title, $post_id = null ): string { $comment_count = (int) … Read more

Adding count also to parent categories

You could add this to your code: function custom_add_count_on_archive_title( $title ) { $term = get_queried_object(); $term_id = get_queried_object()->term_id; if( $term instanceof WP_Term && ‘category’ === $term->taxonomy ) { $children_terms = get_terms(array( ‘taxonomy’ => ‘category’, ‘child_of’ => $term_id, )); $total_count = 0; if (!empty($children_terms) && !is_wp_error($children_terms)) { foreach ($children_terms as $child_term) { $total_count += $child_term->count; } … Read more

Hide load more button if no more post in selected category

I believe you should pass one more label “How many posts remain to be seen” in your $response array in function filterPosts() You know the total number of posts based WP_Query that exist in the database $filter_query = new WP_Query($filter_args); $total_query_posts = $filter_query->found_posts; So, then you have to calculate it based on paged and posts_per_page, … Read more

How to get total posts count for each date?

Instead of the second loop, do the following: Count the posts per date Display them as you will // Count the posts per date $count = []; foreach ( $posts as $post ) { $date = get_the_date( ‘Y-n-j’, $post ); $count[ $date ] = ! isset( $count[ $date ] ) ? 1 : $count[ $date … Read more

Adding a posts count in archive pages

If the theme your’re using doesn’t do anything fancy, but uses the_archive_title() to render the “Lignano Sabbiadoro”, then you should be able to modify it with the get_the_archive_title filter. Something along these lines. add_filter(‘get_the_archive_title’, ‘my_get_the_archive_title_filter’, 10, 3); function my_get_the_archive_title_filter(string $title, string $original_title, string $prefix): string { if (! is_category()) { return $title; } $current_category = … Read more

Can I count every article following extracted meta value?

Use array_count_values() (untested): <?php $posts = get_posts( array( ‘numberposts’ => -1, ‘category_name’ => ‘bird’, ‘order’ => ‘ASC’, ) ); if ( $posts ) { foreach( $posts as $post ) { $species[] = get_post_meta( $post->ID, ‘species1’, true ); $species[] = get_post_meta( $post->ID, ‘species2’, true ); } } $species = array_filter( $species ); $counts = array_count_values( $species … Read more

Count the number of matching post names in foreach loop

I would get the count of a variable number of repeated titles by using an indexed array. $theposts = get_posts( array( ‘post_type’ => ‘post_subscriber’, ‘post_status’ => ‘publish’, ‘numberposts’ => -1, ) ); // project titles counter, outside the loop $project_titles = array(); foreach( $theposts as $p ): $project_name = get_post_meta($p->ID, ‘project’, true); echo ‘<ol>’; echo … Read more

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