WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

Im using wordpress 3.1.1, in frontpage i need to display only the media uploads, now im using this acction:

add_action( 'parse_query', 'custom_query' );

function custom_query( &$query ) {

  $query->set( 'post_type', array('attachment') );


add_filter( 'pre_get_posts', 'my_get_posts' );

function my_get_posts( &$query ) {

  if ( is_home() || is_frontpage() ) {

    $query->set( 'post_status', 'inherit' );
    $query->set( 'post_type', 'attachment' );


  return $query;


But doesnt work.

Any help is working.

share|improve this question
change media to attachment – Bainternet Apr 7 '11 at 17:23
I did it but doesnt work. Above I pasted the code im using. – José Pablo Orozco Marín Apr 7 '11 at 23:27
Nope, sorry, now is working with the add_filter. Thank you Bainternet – José Pablo Orozco Marín Apr 7 '11 at 23:31
@Bainternet: Can you move that comment to an answer? – Jan Fabry Apr 8 '11 at 5:49
@Jan: can, and done. :) – Bainternet Apr 8 '11 at 11:20
up vote 2 down vote accepted

You almost have it right, it should be attachment instead of media since all media uploads are "called" attachments" in WordPress, so:

 $query->set( 'post_type', 'attachment' );
share|improve this answer

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.