#StackBounty: #categories #loop #gallery Default WP Gallery – show only galleries of a certain category

Bounty: 100

I am using WordPress’s default Gallery and adding categories to them. I now created a shortcode with a loop to get the Galleries to a page:

if(! function_exists('test_shortcode')){
function lv_gallery_style_one_shortcode($atts, $content = null){
    extract(shortcode_atts( array(
        ), $atts) );

        $port=array('post_type' => 'gallery', 'category_name' => 'beach', 'showposts' => -1 );
        $loop=new WP_Query($port);
        while ( $loop->have_posts() ) : $loop->the_post(); 

        // HERE IS THE LOOP

        return $html;
add_shortcode('gallery_test', 'test_shortcode' );

I know that the loop worked just fine because when I remove 'category_name' => 'beach' it displays all the categories.

This is just an example code. In the complete version, the category name will be a parameter to enter in the shortcode, that is why I would like to do it like this.

Any ideas on how to get this to work?

Any suggestions are appreciated :).


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.