add_shortcode( 'faq', 'wpse105856_shortcode_callback' );
function wpse105856_shortcode_callback( $atts ) {
extract( shortcode_atts( array(
'category' => ''
), $atts ) );
$args = array(
'numberposts' => -1,
'orderby' => 'menu_order',
'order' => 'ASC',
'post_type' => 'faq'
));
if ( ! empty( $category ) ) {
$args['category_name'] = $category;
}
$posts = get_posts( $args );
$faq = '<div id="faq-accordion">'; //Open the container
foreach ( $posts as $post ) { // Generate the markup for each Question
$faq .= sprintf(('<h3><a href="">%1$s</a></h3><div>%2$s</div>'),
$post->post_title,
wpautop($post->post_content)
);
}
$faq .= '</div>'; //Close the container
return $faq; //Return the HTML.
});
Note: Even though the WP_Query parameter is called category_name
, it expects to be given a slug.