Support » Fixing WordPress » Display List Of Drafts To Subscribers

  • Hi,

    I simply want to have a list of current drafts available for the subscriber to view on their dashboard. It will need to be automatically updated etc when a draft is created and removed etc.

    Ive been searching for a while and cant find any solutions.

    Hope someone can help with this one.

    Thanks!

Viewing 15 replies - 1 through 15 (of 17 total)
  • esmi

    (@esmi)

    Forum Moderator

    You’d need to use query_posts create a custom query that pulled only draft posts. Something like:

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args= array(
    	'post_status' => 'draft',
    	'paged' => $paged
    );
    query_posts($args);
    ?>

    just before the start of the Loop in a custom page template should work.

    Hi esmi,
    Thanks for the reply!
    This works, however its not really what im after.

    What i need is for a list of draft names to appear on the subscribers dashboard, once the subscriber logs in.
    The above code placed all drafts on a page, in their entirity.

    As an example i have made up an image of what it should look like;
    [img]http://i47.tinypic.com/2rxheo1.jpg[/img]

    It needs to movable aswell, so the subscriber can place it anywhere they wish on the dashboard.

    The recent drafts list appears on the administrators dashboard, i would basically like this to show on the subscribers dashboard, minus having the draft links clickable (viewable only)

    Thanks again.

    Any ideas anyone?

    Thanks.

    esmi’s code is still what you need (minus the $paged part possibly), you just aren’t going to put it in a page template. You are going to put it in a dashboard widget instead.

    Thanks apljdi,
    Ive read through the documentation but im still unsure as to where the code should be placed within my files.

    Any guidance on where it should be placed would really be appreciated.

    Thanks for your time.
    – K.O

    You have basically two choices– your theme’s functions.php or a plugin. Inserting the code into functions.php is easiest and quickest and should work just fine as long as you don’t mind that it will only work when your theme is active.

    Setting it up within the themes functions is fine.

    Below is the code in the functions file. Where can i slot in esmi’s code? I’ve tried it on my own which crashed my site.

    <?php
    if ( function_exists('register_sidebar') )
        register_sidebar(array(
            'before_widget' => '<div class="sidebar-box"><div class="sidebar-box-top"><div class="sidebar-box-bottom">',
            'after_widget' => '</div></div></div>',
            'before_title' => '<h3>',
            'after_title' => '</h3>',
        ));
    
    //GsL98DGtpo0W

    Thanks!

    I think what K.O is asking, is how to pull a list of draft posts into a dashboard widget for subscribers only…

    K.O take a look at the link provided previously, namingly this area.
    http://codex.wordpress.org/Dashboard_Widgets_API#Add_an_Example_Widget

    You see this part..

    echo "Hello World, I'm a great Dashboard Widget";

    This is where you’d need to run your own query, and format the data returned from the query..

    If you want some help doing that, just ask… i’ll help you if necessary..

    Hey t31os_,

    I think what K.O is asking, is how to pull a list of draft posts into a dashboard widget for subscribers only…

    Thats exactly what im after!

    If you could help me out, that would really be fantastic. Even with the documentation im still unsure of the files needed to edit and where to place the code within them.

    Thanks!

    Ok. Take the code from the codex and cram in esmi’s code from earlier in the thread.

    // Create the function to output the contents of our Dashboard Widget
    
    function example_dashboard_widget_function() {
    	// Display whatever it is you want to show
    	$args= array(
    	'post_status' => 'draft'
    );
    $drafts = query_posts($args);
    // $drafts = new WP_Query($args);
    print_r($drafts);
    } 
    
    // Create the function use in the action hook
    
    function example_add_dashboard_widgets() {
    	wp_add_dashboard_widget('example_dashboard_widget', 'Example Dashboard Widget', 'example_dashboard_widget_function');
    } 
    
    // Hook into the 'wp_dashboard_setup' action to register our other functions
    
    add_action('wp_dashboard_setup', 'example_add_dashboard_widgets' );

    You’ll notice a commented line just after the query_posts() call. You’ve got two options. query_posts() or create a new WP_Query object. query_posts is supposed to change the main page loop only so it can sometimes jack things up if used to make a secondary loop. I lean toward the new WP_Query method.

    Now, all you need to do is format the output.

    Great! its now displaying on my dashboard.
    However its not displaying current drafts, its listing the latest posts that are on the first page of my website.

    Any chance you could help me out in setting the output to simply list the current draft titles? Thanks be lost without the help.

    K.O

    I thought that 'post_status' => 'draft' would do it. Did you use query_posts or new WP_Query?

    Hey apljdi,
    WP_Query was used.

    Ok so what i gathered from your post was to uncomment the line and add in either query_posts or WP_Query, on the line:
    // $drafts = new WP_Query($args);

    With this done the widget shows on my subscribers dashboard but displays lots of random php code:

    WP_Query Object ( [query_vars] => Array ( [post_status] => drafts [error] => [m] => 0 [p] => 0 [post_parent] => [subpost] => [subpost_id] => [attachment] => [attachment_id] => 0 [name] =>
    this goes on for quite a while

    Then it just lists off the posts on my homepage, images and text included.

    The code im currently using, pretty much the same as what you pasted above:
    `// Create the function to output the contents of our Dashboard Widget

    function example_dashboard_widget_function() {
    // Display whatever it is you want to show
    $args= array(
    ‘post_status’ => ‘drafts’
    );
    $drafts = query_posts($args);
    $drafts = new WP_Query($args);
    print_r($drafts);
    }

    // Create the function use in the action hook

    function example_add_dashboard_widgets() {
    wp_add_dashboard_widget(‘example_dashboard_widget’, ‘Upcoming Posts’, ‘example_dashboard_widget_function’);
    }

    // Hook into the ‘wp_dashboard_setup’ action to register our other functions

    add_action(‘wp_dashboard_setup’, ‘example_add_dashboard_widgets’ );

    Ive absolutely no knowledge of php so please forgive me! :/

    Thanks! 🙂

    With this done the widget shows on my subscribers dashboard but displays lots of random php code:

    That’s not random. That is a string representation of the WP_Query object. That is what print_r() does, more or less. var_dump() does roughly the same thing but with information about variable type also. What you need to do is Loop though and format those results however you want. But if it just lists off the published pages on your home page, there is something wrong with the query. Go ahead and paste the whole block of code in the pastebin.

    Does seem to work with query_posts just fine…
    http://wordpress.pastebin.ca/1774730
    NOTE: Change the role administrator to subscriber to test the code. Also although i mentioned query posts, i actually used a new query in the code, just to be safe..

    Anyhow, i’m wondering if it would be easier to just conditionalise the built in recent posts widget, or is that not suited/desired in this use case?

Viewing 15 replies - 1 through 15 (of 17 total)
  • The topic ‘Display List Of Drafts To Subscribers’ is closed to new replies.