Created
March 22, 2013 04:57
-
-
Save spencejs/5219042 to your computer and use it in GitHub Desktop.
Drafts Dashboard Widget For Custom Post Type In Wordpress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Drafts Dashboard Widget For Custom Post Type | |
| function project_drafts(){ | |
| $posts_query = new WP_Query( array( | |
| // Leave this as "post" if you just want blog posts | |
| 'post_type' => 'projects', | |
| 'post_status' => 'draft', | |
| 'posts_per_page' => 5, | |
| 'orderby' => 'date', | |
| 'order' => 'DESC' | |
| ) ); | |
| $posts =& $posts_query->posts; | |
| if ( $posts && is_array( $posts ) ) { | |
| // Output posts | |
| } else{ | |
| _e('There are no published posts.'); | |
| } | |
| $list = array(); | |
| foreach ( $posts as $post ) { // Loop through our array | |
| $url = get_edit_post_link( $post->ID ); // The URL to the "Edit" post page | |
| $title = get_the_title( $post->ID ); // The title of the post | |
| $chars = 30; // Our character limit | |
| $notes = get_post_meta($post->ID, '_ttrust_notes_value', true); | |
| $item = "<h4><a href='$url' title='" . sprintf( __( 'Edit “%s”' ), esc_attr( $title ) ) . "'>" . esc_html($title) . "</a> <abbr title='" . get_the_time(__('Y/m/d g:i:s A'), $post) . "'>" . get_the_time( get_option( 'date_format' ), $post ) . '</abbr></h4>'; | |
| if ( $notes = preg_split( '#\s#', strip_tags( get_post_meta($post->ID, '_ttrust_notes_value', true) ), $chars+1 , PREG_SPLIT_NO_EMPTY ) ) | |
| $item .= '<p>' . join( ' ', array_slice( $notes, 0, $chars ) ) . ( $chars < count( $notes ) ? '…' : '' ) . '</p>'; | |
| $list[] = $item; | |
| }// End the foreach loop | |
| // Output the posts... | |
| ?> | |
| <ul> | |
| <li><?php echo join( "</li>\n<li>", $list ); ?></li> | |
| </ul> | |
| <?php | |
| } | |
| function register_widgets(){ | |
| wp_add_dashboard_widget( 'our-css-id', 'Recent Drafts - Projects', 'project_drafts'); | |
| } | |
| add_action('wp_dashboard_setup', 'register_widgets' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment