WordPress.org

Ready to get started?Download WordPress

Forums

using get_posts to return ONLY attachments with audio/mpeg mime type (3 posts)

  1. mortal
    Member
    Posted 4 years ago #

    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

  2. mortal
    Member
    Posted 4 years ago #

    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.

  3. jimmyink
    Member
    Posted 3 years ago #

    Thanks for posting that!

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

Topic Closed

This topic has been closed to new replies.

About this Topic