Support » Plugin: Media Categories » get all media from a category in my post

Viewing 1 replies (of 1 total)
  • Lee

    (@romanempiredesign)

    <?php
            $cat = "";
    
            if (is_page('1')) {
    
    	$cat = "1";
    
    	} else {
    
            $cat = "2";
    	}
    
    	$args = array(
                'post_type' => 'attachment',
                'numberposts' => -1,
                'post_status' => null,
                'category' => $cat );
    
            $attachments = get_posts( $args );
                if ( $attachments ) {
                    foreach ( $attachments as $attachment ) {
                        echo '<li>';
                        echo wp_get_attachment_image( $attachment->ID, 'full' );
                        //echo apply_filters( 'the_title', $attachment->post_title );
                        echo '</li>';
                    }
                 }
    ?>

    This will return all of the media from a certain cateogry you specify for a certain page you specify. I included an option to display the media post title but commented it out. if you want to use that, uncomment it.

    This should be what you need and what anyone else who wants to know how to programmatically invoke this plugin needs.

Viewing 1 replies (of 1 total)
  • The topic ‘get all media from a category in my post’ is closed to new replies.