WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to write a shortcode that works in conjunction with Contact Form 7 to display the current user that is logged in posts.

I have been able to get it to work with regular posts using this code here:

wpcf7_add_shortcode('postdropdown', 'createbox', true);
    function createbox(){
    global $post;
    $args = array('numberposts' => 0);
    $myposts = get_posts( $args );
    $output = "<select name='cursus' id='cursus' onchange='document.getElementById(\"cursus\").value=this.value;'><option></option>";
    foreach ( $myposts as $post ) : setup_postdata($post);
        $title = get_the_title();
        $output .= "<option value='$title'> $title </option>";

    $output .= "</select>";
    return $output;

However i am not sure how to go about adapting it for to display only the posts that the currently logged in user posted.

Any help and direction on this would be welcome. Thank you :)

share|improve this question
up vote 1 down vote accepted

Use 'author' => get_current_user_id() as an argument for get_posts(). This will restrict the found posts to these of the user which is currently logged in.

The best reference for the available parameters is still WP_Query::parse_query() in wp-includes/query.php. It is not exactly an atomic function, but you can find parameters not documented elsewhere – like this one.

Tow notes abut your code:

  1. Your onchange handler looks a little bit strange. It doesn’t do anything, does it?
  2. Do not use get_the_title() for attribute values. The post title can contain markup.
    Use the_title_attribute( array ( 'echo' => FALSE ) ); instead.
share|improve this answer
Thank you. I was having a major brain fart. This worked perfectly. :) – Nicole Dec 4 '12 at 21:39
@Nicole I made a small update. – toscho Dec 4 '12 at 21:50
I actually removed the onchange as it was used for something else. However I did change the title. Thanks for the update. :) – Nicole Dec 4 '12 at 23:14

Your Answer


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.