0

I have many child galleries organized by their parent galleries (multiple parent galleries with several child galleries under).

I would like to create a shortcode that is able to query all the child galleries under a specified parent gallery. I'm having a bit of difficulty... anyone care to help me out?

This is the function that I have so far:

function display_gallery_cards($atts) { 
global $post; 

    $defaults = array(
        'sort_column' => menu_order,
        'title_li' => '',
        'child_of' => '',
        'depth' => 1,
        'echo' => 0,
        'parentgal' => '',
        'walker' => new Thumbnail_walker()

    );
    $args = wp_parse_args( $args, $defaults );

    $childpages = wp_list_pages(array(
        'sort_column' => menu_order,
        'title_li' => '',
        'child_of' => $args['parentgal'],
        'depth' => 1,
        'echo' => 0,
        'walker' => new Thumbnail_walker()
    ));

    if ( $childpages ) {
        $string = '<ul class="two-columns">' . $childpages . '</ul><div class="clearfix"></div>';
    }
return $string;
}
add_shortcode( 'list-cards', 'display_gallery_cards' );

When I do [list-cards parentgal='941'] the output displays fine, but it's displaying the wrong pages. Am I passing on the "parent gallery" post ID correctly?

5
  • In your function $parentgal variable doesn't exist. As far as I can tell in your given functions code you're not doing anything with the passed $atts variable either. I suggest checking out the wp_parse_args() function. and edit your question ( using the edit link above ) to update your functions code.
    – Howdy_McGee
    Commented Sep 20, 2017 at 21:07
  • @Howdy_McGee I've edited my code, does this look right?
    – Isaiah Y
    Commented Sep 20, 2017 at 21:14
  • So using your code above, when you view the page with the short code posted in your question that has the id passed to it 941 you don't see the subpage that belong under page id 941?
    – Howdy_McGee
    Commented Sep 20, 2017 at 21:23
  • @Howdy_McGee that's correct. It seems to be displaying random parent/top-level posts, instead of child posts.
    – Isaiah Y
    Commented Sep 20, 2017 at 21:27
  • @Howdy_McGee solved! Solution posted below.
    – Isaiah Y
    Commented Sep 20, 2017 at 22:06

1 Answer 1

1

I had to set the post type in the query.

'post_type' => 'gallery'

Problem solved!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.