Get array of shortcodes within string

function wpse250308_get_questions() { global $post; if ( preg_match_all(‘/\[question(.*?)\]/’, $post->post_content, $questions ) ) { $questions = array_key_exists( 1 , $questions) ? $questions[1] : array(); // $questions will contain the array of the question shortcodes //Do your stuff } } $post isn’t available before wp. So, you have to hook on it or actions that fires later.

Shortcode question

Why not like this: //function to generate error messages for bid form function generate_error_msg($type, $message){ global $error_msg; if($type == “success”) { $error_msg = “<div class=”success”>{$message}</div>”; } else { $error_msg = “<div class=”error”>{$message}</div>”; } } //Creates table, displays and validates bid form, and inserts valid bid data into table. function bid_form_display(){ //$error_msg = ”; global $wpdb; … Read more

Using a Shortcode to List Posts from Multiple Categories

Maybe you can make it so that you can use the shortcode like [list-products categories=”1,2,3″], and then explode them as an array to insert them as your terms? <?php function list_products_func($atts) { $a = shortcode_atts(array( ‘categories’ => ”, ), $atts); // Check for multiple categories by comma if ( strpos( $a[‘categories’], ‘,’ ) !== false … Read more

Split shortcodes to array of shortcodes

WordPress already has built in support for Nested Shortcodesprovided their handler functions support it by recursively calling. So if you have for example: [tag-a] [tag-b] [tag-c] [/tag-b] [/tag-a] As long as you recursively call do_shortcode in your shortcode function, all the shortcodes would be parsed. So you would define the functions for your shortcodes as … Read more

wordpress shortcode not working

Point-1: it’s not clear where you are getting $order_id from. I’m assuming it’s in the Shortcode. Point-2: You don’t need to. use ob_* functions for returning Shortcode replacement content, simply returning is enough. Assuming other parts of your CODE is correct, below is the possible CODE that should work: If the shortcode is implemented in … Read more