Add “showing posts x to x of y” in custom post type paginated loop

All query objects have a few built in vars that can help you display this. Assuming your custom query object is $query: The total number of posts across all pages is $query->found_posts The total number of posts for the current page is $query->post_count The current page number is $query->query_vars[‘paged’] The number of posts per page … Read more

Add estimated value for a post according to the number of words

Here’s an idea for a starting point, by looking how the word counting is done in the /wp-admin/js/post.js file: /** * Testing word price calculations */ add_action( ‘after_wp_tiny_mce’, function() { ?><script> ( function( $ ) { $( function() { // Init var $content = $( ‘#content’ ), $count = $( ‘#wp-word-count’ ).find( ‘.word-count’ ), total_price … Read more

How to count the number of archives there are

Notes: Currently you’re echo-ing the output of wp_get_archives(). In order to return it, we must set the echo input parameter to false. You’re assuming the output of wp_get_archives() is an array, but it’s a string. Workaround: Here’s one way, by counting the <li> instances, with the html format: $args = [ ‘parent’ => 0, ‘hide_empty’ … Read more

How to show the number of website visitors in my theme

Here is what you need to use for the expected result: <p> Today’s Views: <span> <?php echo wp_statistics_visit(‘today’); ?> </span></p><br><br> <p>Yesterday’s Views: <span> <?php echo wp_statistics_visit(‘yesterday’); ?> </span></p><br><br> <p>All times Views: <span> <?php echo wp_statistics_visit(‘total’); ?> </span></p><br><br>

Multisite – maximum number of users with specific role

Ok here is how I did it: add_action( ‘editable_roles’ , ‘hide_editable_roles’ ); function hide_editable_roles( $roles ){ $blog_id = get_current_blog_id(); // Get current subsite id switch($blog_id) { // Define different max agents numbers depending on subsite id case 6: $max_agents = 10; //for subsite id#6 we can have maximum 10 agents break; case 7: //for subsite … Read more

How to add category post count in main navigation menu [closed]

This can be achieved many ways. But, the below method is most prominent to me. add_filter(‘the_title’, ‘wpse165333_the_title’, 10, 2); function wpse165333_the_title($title, $post_ID) { if( ‘nav_menu_item’ == get_post_type($post_ID) ) { if( ‘taxonomy’ == get_post_meta($post_ID, ‘_menu_item_type’, true) && ‘category’ == get_post_meta($post_ID, ‘_menu_item_object’, true) ) { $category = get_category( get_post_meta($post_ID, ‘_menu_item_object_id’, true) ); $title .= sprintf(‘ (%d)’, $category->count); … Read more

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)