How can I count ACF sub_field with a certain value

PHP’s count() function is generally used to count elements in an array, but you’re counting the value of a string, and that always returns 1. You can just add 1 in your if statement. Something like this: if (have_rows(‘candidates’)): $total = 0; while (have_rows(‘candidates’)): the_row(); $position = get_sub_field(‘candidate_position’); if ($position == “Mayor”) { $total++; }; … Read more

Get post number both in the loop and in the post

You can do it like this on single post page following this answer. The code may need some tweaking to meet your exact requirements. Put this in functions.php of your theme class MY_Post_Numbers { private $count = 0; private $posts = array(); public function display_count() { $this->init(); // prevent unnecessary queries $id = get_the_ID(); echo … Read more

Loop is crazy – one row displays wrong count of posts [closed]

For your clearfix wrapper you are doing it wrong. You have this: $counter = 0; while ( $loop->have_posts() ) : $loop->the_post(); if ($counter % 4 == 0) : echo $counter > 0 ? “</div>” : “”; // close div if it’s not the first echo “<div class=”clearfix”>”; endif; // BUILDS INTERNAL DIVS $counter++; endwhile; So … Read more

I am trying to get cutom post cout by month of current taxonmy term

you can do that with WordPress functions like that : $post_type = “tesekkur”; $timestamp_start = strtotime(“first day of next month -1 year midnight”); $start = date(“Y-m-d H:i:s”, $timestamp_start); $posts = get_posts([ “nopaging” => TRUE, “post_type” => $post_type, “date_query” => [ “after” => $start, ], ]); // sort by month $tab = []; foreach ($posts as … Read more

Author comment count in author page

all you have to do is to add an param: /* user commnet count */ function get_comment_count( $user_ID ) { global $wpdb; $count = $wpdb->get_var( $wpdb->prepare( “SELECT COUNT(comment_ID) FROM {$wpdb->comments} WHERE user_id = %d “, $user_ID ) ); return $count; } <?php echo get_comment_count( <USER_ID> ); ?> PS. I’ve added some proper escaping in your … Read more

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

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