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 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>";

        endforeach;
    $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
add comment

1 Answer 1

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
add comment

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.