the code should be instead
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 );
//Here is where I am trying to dynamically add a new number to the faq-accordion div
$num = 0;
$faq = '';
$faq = '<div class="question-wrapper">';//wrapper div for all the questions
//Generate div for each question
foreach ( $posts as $post ) {
$faq .= '<div id="faq-accordion'.++$num.'">'; //Open the container
// 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
}
$faq .= '</div>';//close the wrapper
return $faq; //Return the HTML.
};
As you commented, for your need in comment you can use $post->ID in div id
like
echo '<div id="'.$post->ID.'">';