• Hi,

    I’m hoping to show a list of PDFs by category in a widget using Enhanced Media Library. Does anybody have an idea as to how that piece of code might look? (I’m assuming I can’t do this with shortcodes, but of course, that would be ideal!)

    thank you,
    Lisa

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author webbistro

    (@webbistro)

    Hi @lisath,

    Sorry for the late reply! We are doing our best to include the feature (shortcode) to the upcoming release. Right now you can try the code like this:

        $args = array(
            'post_type' => 'attachment',
            'post_status' => 'inherit',
        
            // for PDFs
            'post_mime_type' => 'application/pdf',
        
            // if you need PDFs from a specific media category
            'tax_query' => array(
                array(
                    'taxonomy' => 'media_category', // your taxonomy
                    'field' => 'id',
                    'terms' => 7 // term id (id of the media category)
                )
    	)
        );
        $query = new WP_Query( $args );
    
        if ( $query->have_posts() ) { ?>
        
            <ul>
                <?php while ( $query->have_posts() ) : $query->the_post(); ?>
    
                    <li>
                        <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> <?php echo filesize( get_attached_file( $attachment->ID ) ) . ' bytes'; ?>
                    </li>
                
                <?php endwhile; ?>
            </ul>
        
        <?php } 
        else {
    	// some output for no PDFs found
        }
    
        wp_reset_postdata();

    Best,
    -Nadia

    Thread Starter lisath

    (@lisath)

    Hi Nadia,

    Thank you for this. I hope you don’t mind a rookie question or three, but . . .

    1) For ‘media_category’ I’d use the slug from the media category I createed?
    2) To get ‘term’ I’d use the post id I see at the bottom of the browser when I hover over the name of the media category?
    and importantly,
    3) Would I wrap this whole piece of code in “<?php” & “?>” in the (php code) widget I’m using?

    all best,
    Lisa

    Plugin Author webbistro

    (@webbistro)

    Hi Lisa,

    Sorry for my silence. For some reason I didn’t receive notification about your message.

    (1) No, it’s the name of the whole taxonomy (sometimes the slug can be different) you can see it on Settings > Media Taxonomies per taxonomy. Click “Edit” next to a taxonomy you need and find “Taxonomy Name” field. If you use Media Taxonomies then the name is “media_category”, and you don’t have to change anything in the code.

    (2) That’s correct.

    (3) Of course, since it’s PHP code, it should be wrapped in <?php ?>.

    I just made sure that I set “Notify me of follow-up replies via email” for this ticket and will check it anyway, so please feel free to ask questions if they are still actual for you.

    Sorry again.

    Best,
    -Nadia

    pequet

    (@pequet)

    Hi Nadia

    Do you have an ETA for this ‘upcoming release’ adding support pdf files? Or a beta version of the plugin? Our media library is exclusively pdf. (I am about to purchase the Pro version.) Thank you!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘List of Documents within a category’ is closed to new replies.