Post loop count is not in order

a) Try to initialize the $count variable before your loop: $counts=0; $loop = new WP_Query( array( ‘post_type’ => ‘focus-areas’, ‘posts_per_page’ => -1 ) ); while ( $loop->have_posts() ) : $loop->the_post(); $counts++; echo $counts; echo ” – “; endwhile; b) or use the current_post method (starts at 0) of WP_Query: $loop = new WP_Query( array( ‘post_type’ … Read more

Count post views in loop

Few remarks: You should consider using a prefix on your meta key, for example lars_views, to minimize the risk of other plugins messing around with it. If you want to hide it from the edit screen, you can use an underscore: _lars_views. Consider wrapping the part of your code, that updates the counter, with if( … Read more

Display count of new members registered today [closed]

function bp_registrations_today($activated = false) { global $wpdb; $query = “SELECT COUNT(ID) FROM {$wpdb->prefix}users WHERE DATE(user_registered) = CURDATE()”; if ( $activated ) { $query .= ” AND user_status = 0″; } return $wpdb->get_var($query); } To get the number of users registered today, call the function as echo bp_registrations_today(); To get the number of users registered today … Read more

How do I count columns on a custom WPDB query?

Under straight mysql core functions you would use mysql_num_fields, but through $wpdb (wordpress database object), I found the following worked for me. $result = $wpdb->get_results(‘DESCRIBE ‘.$table,ARRAY_A); $columns = array(); foreach($result as $row) { $columns[] = $row[‘Field’]; } $num_fields = count($columns);

Give each posts in a loop a number in sequence

As this is a presentational thing, I’d be inclined to use CSS (there are of course ways of doing it in PHP, and others may disagree.) You’d make use of the counter-reset and counter-increment properties. CSS counters can be applied to any element, not just ordered-lists (<ol></ol>) and added using pseudo-elements and you can control … Read more

How can I count only guests comments?

You can use these inside the loop, or in comments.php //The author of current post $author_ID = get_the_author_meta(“ID”); //The current post ID $p_ID = get_the_ID(); //Number of guest comments echo count(get_comments(array( ‘post_id’ => $p_ID, ‘author__not_in’ => array($author_ID) ))); More: https://codex.wordpress.org/Function_Reference/get_comments

Post Views / Hit Counter Problem?

Use the following functionto set views manually function setPostViewsManually($postID, $viewCount) { $count_key = ‘post_views_count’; $count = get_post_meta($postID, $count_key, true); update_post_meta($postID, $count_key, $viewCount); } You can run this code by <?php setPostViewsManually(get_the_ID(), 1234); ?> The above code will set the view to ‘1234’ for the current post. Run this function carefully else your new views will … Read more

Get total views of all posts by author

Gathering page view statistics is inherently write operation, which is inherently heavy on resources. There are no appropriate mechanisms in WP for high volume writes at low resource consumption. Your best bet is using external analytics system/service and retrieving page view data from it.

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