I want to look for all strings in my theme located between my enclosing shortcode [question] desired string [/question].
Then I want to output the so collected strings somewhere in my theme , e.g. listing all those questions and linking them each to their containing post.
The idea behind is that I am building a wordpress blog where I write down all the things i learned in blog posts. basically so far for myself. When I have questions about a certain topic I wanna note them down in the blog post between those tags. To find and answer the questions afterwards I want to use this filter function.
So far I was able to get one string between the shortcode using the Options API and this code. But it only lets me save one question at a time while I want to store all strings that are located between [question][/question] shortcodes. Floemi suggested using the Settings API. I am trying to get my head around but there might be a more semantic solution to this.
function question_shortcode($atts, $content = null ) {
global $question_shortcode_text;
$question_shortcode_text = $content;
echo "<h2 class='question'>" . $question_shortcode_text . "</h2>";
update_option( 'question_shortcode_option', $question_shortcode_text );
};
add_action( 'save_post', 'question_shortcode' );
add_filter( 'the_content', 'testing_var');
function testing_var( $content ) {
$question_from_shortcode = get_option( 'question_shortcode_option' );
$content = $question_from_shortcode . $content;
return $content;
}
add_shortcode( 'question', 'question_shortcode' );