title: Dynamic shortcodes and functions in WordPress
body: <p>I am having a bit of an issue with autogenerating shortcodes, based on database entries.</p>
  
  <p>I am able to get a normal shortcode working i.e:</p>
  
  <pre><code>function route_sc5() {
          return "&lt;div&gt;Route 5&lt;/div&gt;";
      }
      add_shortcode('route 5','route_sc');
  </code></pre>
  
  <p>and the following shortcode to activate it would be <code>[route 5]</code></p>
  
  <p>This works. But what I need is the shortcode to be produced for each database entry. something like:</p>
  
  <pre><code>$routes = $wpdb-&gt;get_results( $wpdb-&gt;prepare("SELECT * FROM wp_routes") );
  foreach($routes as $route)
  {
      function route_sc$route-&gt;id () {
          return "&lt;div&gt;Route $route-&gt;id&lt;/div&gt;";
      }
      add_shortcode('route $route-&gt;id','route_sc$route-&gt;id');
  }
  </code></pre>
  
  <p>The above is just an example of how I want it to work. Not literally the code I am using. How would I go about achieving this? ):
  Thanks.</p>