Title: [shortcode &#8211; recursive ] outside loop ?
Last modified: August 19, 2016

---

# [shortcode – recursive ] outside loop ?

 *  [exstyle](https://wordpress.org/support/users/exstyle/)
 * (@exstyle)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/shortcode-recursive-outside-loop/)
 * Hello,
 * First time I code into WordPress and i’m having a little problem.
 * **Context**
 * I’m using LimeSurvey, an open Source API which help me doing nice survey. The
   thing is that I would like it to be integrated inside my WorldPress site.
 * For that, i’m using a plugin called Embed Iframe. It works fine!
 * **It gets tricky**
    For some Survey, respondent have to use a token (a specific
   key, that allow the user to respond to the survey), which is manage with limesurvey
   backoffice. Using user_meta, i have map WorldPress users profile with their respective
   Token from LimeSurvey.
 * While accessing a survey through a URL, I need to provide the Token and Survey
   ID.
 * Meaning, for the current registered user reading a specific post, I need to provide
   the survey related to the post (post_meta), and the token related to the user(
   user_meta).
 * [http://url/survey?sid=22&token=222](http://url/survey?sid=22&token=222)
 * To do so, I’ve created a new shortcode, ‘ilimesurvey’. The following function
   has been adding into the functions.php of my theme:
 *     ```
       // Function LimeSurvey
       function limesurvey()	{
   
       	if(is_user_logged_in()){
   
       		global $current_user;
       		get_currentuserinfo();
   
       		echo 'hello, ' . $current_user->user_name . "\n";
   
       		$ID = $current_user->ID;
       		$key = 'Token';
       		$single = true;
       		$tokenid = get_user_meta($ID, $key, $single);
   
       		$ID = $_GET['p'];
       		$key = 'limeid';
   
       		if (isset($_GET['p']))	{
       			$limeid = get_post_meta($ID,$key,$single);
       			$iframeTest = '[iframe http://url/limesurvey/index.php?sid='.$limeid.'&lang=fr&token='.$tokenid.' 580 700]';
       			print apply_filters( 'the_content', $iframeTest );
       		}
       		else	{
       			echo "Cliquer sur l'article pour acc&egrave;der au questionnaire";
       		}
   
       		return "<br />";
   
           }
       	else
       	{
       		echo "That message will be repeated x times...";
       		$iframeEssai = '[iframe http://url/limesurvey/index.php?sid=24318&lang=fr 580 700]';
       		print apply_filters( 'the_content', $iframeEssai );
       		return "<br />";
   
       	}
       }
       add_shortcode('ilimesurvey', 'limesurvey');
       ```
   
 * **The problem**
    It’s work fine while i’m reading the post through the post specific
   page.
 * But in the home page, i’ve got some problem. It’s like the function is called
   again and again.
 * I did some trick with the code “if (isset($_GET[‘p’]))”, but by doing so, users
   can’t answer the message directly from the home page !
 * The message “That message will be repeated x times…” is also repeated again and
   again…
 * I suppose it’s related to the loop … It has to be a rookie mistake!

The topic ‘[shortcode – recursive ] outside loop ?’ is closed to new replies.

## Tags

 * [homepage](https://wordpress.org/support/topic-tag/homepage/)
 * [loop](https://wordpress.org/support/topic-tag/loop/)
 * [recursive](https://wordpress.org/support/topic-tag/recursive/)
 * [shortcode](https://wordpress.org/support/topic-tag/shortcode/)

 * 0 replies
 * 1 participant
 * Last reply from: [exstyle](https://wordpress.org/support/users/exstyle/)
 * Last activity: [15 years, 8 months ago](https://wordpress.org/support/topic/shortcode-recursive-outside-loop/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
