Title: add nested shortcode to php in WP_QUERY
Last modified: August 30, 2016

---

# add nested shortcode to php in WP_QUERY

 *  [rudtek2](https://wordpress.org/support/users/rudtek2/)
 * (@rudtek2)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/add-nested-shortcode-to-php-in-wp_query/)
 * I have a theme that uses an accordion that needs nested short codes. I’m trying
   to get it to work in my wp_query.
 *     ```
       [av_toggle_container initial='0' mode='accordion' sort='']
           [av_toggle title='Toggle 1' tags='']
           Toggle Content goes here
           [/av_toggle]
           [av_toggle title='Toggle 2' tags='']
           Toggle Content goes here
           [/av_toggle]
           [/av_toggle_container]
       ```
   
 * There are short codes nested in shortcodes here, and the “av_toggle_container”
   i believe needs to be outside of my while portion of the query. How would i do
   that?
 * This is what i have right now:
 *     ```
       if( $the_query->have_posts() ): ?>
           <?php  echo do_shortcode(
           "[av_toggle_container initial='0' mode='accordion' sort='']");
           while(    $the_query->have_posts() ) : $the_query->the_post();
           $toggletitle =get_the_title();
           $togglecontent = get_the_content();
           echo do_shortcode( "[av_toggle title='".$toggletitle."'tags='']".$togglecontent."[/av_toggle]");
           endwhile;
           echo do_shortcode( '[/av_toggle_container]'); ?>
           <?php endif; ?>
           <?php wp_reset_query();	 // Restore global post data stomped by the_post().
           ?>
       ```
   

Viewing 1 replies (of 1 total)

 *  Thread Starter [rudtek2](https://wordpress.org/support/users/rudtek2/)
 * (@rudtek2)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/add-nested-shortcode-to-php-in-wp_query/#post-6633057)
 * anyone?

Viewing 1 replies (of 1 total)

The topic ‘add nested shortcode to php in WP_QUERY’ is closed to new replies.

## Tags

 * [php](https://wordpress.org/support/topic-tag/php/)
 * [shortcode](https://wordpress.org/support/topic-tag/shortcode/)
 * [wp_query](https://wordpress.org/support/topic-tag/wp_query/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 1 participant
 * Last reply from: [rudtek2](https://wordpress.org/support/users/rudtek2/)
 * Last activity: [10 years, 7 months ago](https://wordpress.org/support/topic/add-nested-shortcode-to-php-in-wp_query/#post-6633057)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
