Advertisement
ryanharne

WP WordPress get Short Code Content

Sep 24th, 2013
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.97 KB | None | 0 0
  1. function get_shortcode_content($shorcode, $post = '', $all = 'id|name', $get = '')
  2. {
  3.     if(empty($post))
  4.     {
  5.         global $post;      
  6.     }
  7.  
  8.     $pattern = get_shortcode_regex();
  9.     if (   preg_match_all( '/'. $pattern .'/s', $post->post_content, $matches )
  10.         && array_key_exists( 2, $matches )
  11.         && in_array( $shorcode, $matches[2] ) )
  12.     {
  13.         preg_match_all('/(' . $all . ')=("[^"]*")/i', trim($matches[3][0]), $all_shortcode_settings);
  14.         if(!empty($all_shortcode_settings))
  15.         {
  16.             if(!empty($get))
  17.             {
  18.                 $id_index = -1;
  19.                 foreach($all_shortcode_settings[1] as $attribute_index => $attribute)
  20.                 {
  21.                     if($attribute == $get)
  22.                     {
  23.                         $id_index = $attribute_index;
  24.                         break;
  25.                     }
  26.                 }
  27.  
  28.                 if( ($id_index >= 0) && (!empty($all_shortcode_settings[2][$id_index])) )
  29.                 {
  30.                     return $all_shortcode_settings[2][$id_index];
  31.                 }
  32.             }
  33.  
  34.             return $all_shortcode_settings;
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement