Default WP Gallery – show only galleries of a certain category

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(
‘title’=>”,
), $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 :).

Thanks.

Read more here:: Default WP Gallery – show only galleries of a certain category

Leave a Reply

Your email address will not be published. Required fields are marked *