WordPress.org

Support

Support » How-To and Troubleshooting » using get_posts to return ONLY attachments with audio/mpeg mime type

using get_posts to return ONLY attachments with audio/mpeg mime type

  • here is my code so far:

    <?php
    $args = array(
    	'post_type' => 'attachment',
    	'mime_type' => 'audio/mpeg',
    	'numberposts' => -1,
    	'post_status' => null,
    	'post_parent' => null, // any parent
    	);
    ?>
    <div class="post" id="page-thumb-list">
    <h2 class="page-title">Audio</h2>
    <?php $posts = get_posts($args);
    foreach ($posts as $post) : start_wp(); ?>
    
    <div class="item-audio">
    
    <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    <?php the_content(); ?>
    </div>
    <?php endforeach; ?>

    but it returns all attachments. any help would be appreciated. thanks in advance

Viewing 2 replies - 1 through 2 (of 2 total)
  • i found a fix.

    i changed mime_type to post_mime_type and it worked!

    awesome. i posted the solution here in case some one else is trying to do the same thing.

    Thanks for posting that!

    I think I’m going to have to add this to the codex.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘using get_posts to return ONLY attachments with audio/mpeg mime type’ is closed to new replies.
Skip to toolbar