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.
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.
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
$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
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
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
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.
In the form you have posted this is more of PHP question – you could use strlen() functions to determine length of original title and apply ellipsis conditionally. However in WP context you should consider using wp_trim_words() since trimming based on words looks tidier and it will take care of appending string of your choice … Read more
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
Set two variables to 0 before the foreach loop. $positive = 0; $negative = 0; Then in your if statement: if($entry[1] < 7){ //increment variable $negative++; echo $entry[1] . ‘ = Negative Feedback<hr>’; }elseif($entry[1] > 8){ //increment variable $positive++ echo $entry[1] . ‘ = Positive Feedback<hr>’; }else{ echo $entry[1] . ‘ = Neutral Feedback<hr>’; } … Read more
Get count of terms with a post and another taxonomy term?