[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).
https://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 https://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èder au questionnaire"; } return "<br />"; } else { echo "That message will be repeated x times..."; $iframeEssai = '[iframe https://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.