Double count view in archive.php
You fire setPostViews twice in ad.php via PHP setPostViews($adID); via JS with your ajax function again. Remove one, and you should be fine.
You fire setPostViews twice in ad.php via PHP setPostViews($adID); via JS with your ajax function again. Remove one, and you should be fine.
get_queried_object error How to show post count by month in the taxonomy page
How to trace/fix false $term->count, rogue term relationships?
Run a couple of queries and a code snippet to calculate the word count for the post content, comments content and tag names on each post. // This query will return the number of words in the post content $post_qry=”SELECT LENGTH(post_content) – LENGTH(REPLACE(post_content, ‘ ‘, ”))+1 from wp_posts where ID=”.$post_id; // This query will return … Read more
/** * Get the author post count for a tax query. * * @link http://wordpress.stackexchange.com/q/159160/1685 * * @param array $tax_query * @return int */ function wpse_159160_get_author_posts_by_tax( $tax_query ) { global $wpdb; $where = get_posts_by_author_sql( ‘post’, true, get_post()->post_author ); $tax_query = new WP_Tax_Query( $tax_query ); $sql = $tax_query->get_sql( $wpdb->posts, ‘ID’ ); return ( int ) $wpdb->get_var( … Read more
If you prefer the $wpdb direct queries you can use something like this: global $wpdb; $count = $wpdb->get_var( “SELECT COUNT(ID) FROM {$wpdb->posts} WHERE post_type=”code” and post_status=”publish”” ); echo $count; In the sql query above change the post_type to whatever you like. This will return count of published posts under specific post type only. If you … Read more
Edit: Re-reading your question I noticed I may have mixed some things up, but the point remains that you should combine these separate queries performed inside the loop, by using variables inside the loop to create a comprehensive list of the query arguments that you can use to perform one query outside the loop. I’ve … Read more
I have successfully returned the counts using the following code. Just in case someone may later view this question. $count = 0; $category = ’45’; foreach ( $array as $post_id ) { if (in_category( $category, $post_id )) { $count++; } } echo $count;
Use get_term_children() $term_id = 2; // use get_queried_object()->term_id; to get the current term id $taxonomy_name=”mypages”; // use use get_queried_object()->taxonomy; to get the current taxonomy name $countchildren = count (get_term_children( $term_id, $taxonomy_name )); echo $countchildren;
The function count_user_posts only accepts a user ID so you arguments are never taken in consideration. Here is a simple function to get the count by status function count_user_posts_by_status($post_status=”publish”,$user_id = 0){ global $wpdb; $count = $wpdb->get_var( $wpdb->prepare( ” SELECT COUNT(ID) FROM $wpdb->posts WHERE post_status = %s AND post_author = %d”, $post_status, $user_id ) ); return … Read more