Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I want to allow user that Post option display on his dashboard. Where User's Can Show only his post. How I manage this. Please Help me.

share|improve this question
    
Please explain post option. –  toscho May 5 '13 at 7:33

1 Answer 1

You seem to be asking 2 questions:

1) How do I place something on the Dashboard?

2) How do I get the links to all posts the current author has written?

One way to place something on the Dashboard is to use a Dashboard widget. The Dashboard Widgets API describes the details, but here is some code based on it.

add_action( 'wp_dashboard_setup', 'ckc_author_posts_dashboard_widget' );

/**
 * This function runs when the 'wp_dashboard_setup' action is
 * called. It adds the widget and calls the function that that fills
 * the widget.
 */
function ckc_author_posts_dashboard_widget() {
    wp_add_dashboard_widget( 'author_posts_dashboard_widget', __( 'Your Posts', 'theme_text_domain' ), 'ckc_author_posts' );
}

/**
 *  This function displays the text in the 'author_posts_dashboard_widget'.
 */
function ckc_author_posts() {
    // Display whatever it is you want to show
    echo "This is where the posts for this author will be displayed.";
}

Add that code to your functions.php theme file. 'theme_text_domain' should be replaced with the text domain for your theme, if you use one. Otherwise leave it as is.

You should end up with a new Dashboard Widget with the text "This is where the posts for this author will be displayed." in it.

To get a list of links for the Author's posts, run a query on the WordPress database. That sounds fancy and technical, but the information is written in (fairly) plain English in the WP_Query Object Reference. Here is the code I used to test for this answer.

/**
 *  This function displays the text in the 'author_posts_dashboard_widget'.
 */
function ckc_author_posts() {
    $current_user = wp_get_current_user();

    // This is the query. Change it to change which
    // posts appear in the while loop below.
    $author_posts = new WP_Query( array(
        'author' => $current_user->ID,
    ) );

    if ( $author_posts->have_posts() ) {

        echo '<ul>';

        while ( $author_posts->have_posts() ) {
            $author_posts->the_post();

            printf(
                "<li><a href='%s'>%s</a> (<a href='%s'>Edit</a>)</li>\n",
                get_permalink(),
                get_the_title(),
                get_edit_post_link()
            );
        }

        echo '</ul>';

    } else {
        echo 'No Post found.';
    }
}

This produces a list of all posts by the current author and adds a link to edit the posts as well. I didn't test it thoroughly, but the query should grab all the posts by this author, published, unpublished, in the trash, etc. If you want something different, you should adjust the arguments in the WP_Query() call.

If you do not want the Edit link replace the printf() code with this:

            printf(
                "<li><a href='%s'>%s</a></li>\n",
                get_permalink(),
                get_the_title()
            );
share|improve this answer
1  
Not sure if the Question as it is deserves such an Answer. +1 for the nice write-up –  brasofilo May 5 '13 at 22:51

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.