Search Count WordPress Theme

If you are in the search results template then you can find out the count by using the below code. global $wp_query; $count = $wp_query->found_posts variable $count contains the count of post against the search.

What is the best way to do this? [closed]

Let’s start with proper indenting your code: <select name=”select-city” onchange=”location = this.value;”> <option value=””>Select a post to read</option> <?php if ( is_user_logged_in() ): global $current_user; wp_get_current_user(); $author_query = array(‘posts_per_page’ => ‘-1′,’author’ => $current_user->ID); $author_posts = new WP_Query($author_query); $numposts = count_user_posts( $user_id ); // <- you can’t use $count_user_posts also – it’s a function, not a … Read more

Count posts published in one particular day: the lighter way

$wp_query->found_posts can be used to get the number of posts. But here are arguments you can use to optimize the query and avoid useless SQL retrievals: cache_results’ => false, // Turns off post caching ‘no_found_rows’ => true, // To optimize when pagination is not required ‘fields’ => ‘ids’ // To only retrieve IDs information, nothing … Read more

How to do simple addition to increase favorites count of my wordpress posts

You can simply do it by adding 300 when displaying count as shown in following code: <?php echo ‘TOTAL POST VIEWS: ‘ .(intval(wpfp_get_current_count()) + 300); ?> and instead of echoing that values in function return it as shown in following code: function wpfp_get_current_count() { global $wpdb; $current_post = get_the_ID(); $query = “SELECT post_id, meta_value, post_status … Read more

Count post + add number =

If you want to count posts of some custom post type, you can try out the WordPress function wp_count_posts() In your case the custom post type is ‘projects’ so you might try this: $count_projects = wp_count_posts( ‘projects’ ); $published_projects = $count_projects->publish; $total = $published_projects + 11; // include your additional projects You can read more … 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.

Counting posts in custom post type by author

i found this code wordpress.org . This code would work in author template. <?php global $wp_query; $curauth = $wp_query->get_queried_object(); $post_count = $wpdb->get_var(“SELECT COUNT(*) FROM $wpdb->posts WHERE post_author=”” . $curauth->ID . “” AND post_type=”post” AND post_status=”publish””); ?> <h2>Post Count: <?php echo $post_count; ?></h2> But if you wish to use it somewhere else then replace $curauth->ID with … Read more

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