Passing child category parameter to shortcode failing
-
I’ve spent several hours trying to find a solution to no avail, so I’m finally giving up and asking the WP community.
The function:
function display_policy_shortlist($atts,$tag){ extract(shortcode_atts(array( 'type' => 'page', 'num' => 10, 'name' => 'policies', 'order_by' => 'title', 'order' => 'asc' ), $atts)); $args = array( 'post_type' => $type, 'category_name' => $name, 'posts_per_page' => $num, 'orderby'=> $order_by, 'order' => $order ); $loop = new WP_Query( $args ); if ($loop->have_posts()) : echo '<ul>'; while ($loop->have_posts()) : $loop->the_post(); echo '<li>'; echo '<a href="'; echo the_permalink(); echo '">'; echo the_title(); echo '</a></li>'; endwhile; echo '</ul>'; endif; } add_shortcode('policy_shortlist','display_policy_shortlist');
Note: I’m aware the use of extract in frowned upon, so please don’t scold me.
The name parameter works just fine with the parent category (policies) or any child category as the default. But if I try to pass a child category to name – say security-policies – it falls back to the default.
My hunch is there is a bit of code I need to explicitly state the name parameter is a child category. I have 13 child categories and my work-around for the moment is to have 13 shortcodes – I’m not diggin’ that.
I’m at a loss. Any feedback or help is greatly appreciated.
- The topic ‘Passing child category parameter to shortcode failing’ is closed to new replies.