Count posts by type including drafts and pending posts

It’s not necessary to use $wpdb, a simple get_posts can handle it. Check WP_Query for the full list of parameters. function count_user_posts_by_type( $userid, $post_type ) { $args = array( ‘numberposts’ => -1, ‘post_type’ => $post_type, ‘post_status’ => array( ‘publish’, ‘private’, ‘draft’, ‘pending’ ), ‘author’ => $userid ); $count_posts = count( get_posts( $args ) ); return … Read more

Auto-Populate Image After Media Upload

In the same call where the image URL is being sent to the editor, you fill up another div with an image source. Like: window.send_to_editor = function(html) { imgurl = jQuery(‘img’,html).attr(‘src’); jQuery(‘#upload_image’).val(imgurl); imgsrc=”https://wordpress.stackexchange.com/questions/82427/<img id=”upload_image” name=”upload_image” src=””+imgurl+'”>’; jQuery(‘#image-holder’).html(imgsrc); tb_remove(); } PS: this is for the Old Thickbox, not for the New 3.5 Uploader, which has very … Read more

How to change the name of the “edit my profile” link in the WordPress admin backend

You could use the wp_before_admin_bar_render hook. You can play with code samples on the Codex page by putting them in your theme’s functions.php. First off you can try examining the object by outputting its contents with print_r(), and you’ll see all the familiar items. I would probably use remove_menu helper and then add a new … Read more

Admin Posts List (edit.php) by post IDs

It can be achieved using pre_get_posts. It is important to prefix all your variable names, id seems not be in the reserved terms list, but anyway this practice avoids any unforeseen bug. /** * Usage: * http://example.com/wp-admin/edit.php?my_pids=4088,4090,4092,4094 */ add_filter( ‘pre_get_posts’, ‘limit_post_list_wpse_96418’ ); function limit_post_list_wpse_96418( $query ) { // Don’t run on frontend if( !is_admin() ) … Read more