0

So I want to create a shortcode for every row in my database. The problem here is that the add_shortcode() requires a shortcode, which I can create a variable for in a foreach loop and a callback function. And I can't seem to figure out how to dynamically create that one for every database entry without entering in manually.

For example

$sqlarray = $wpdb->get_results( "SELECT * FROM wpm6_synopsis", 'ARRAY_A' );

foreach ($sqlarray as $shortcode) {
    $shortcode = $shortcode->name;
    $function = function() { } // I know this is not possible
    // OR
    $function() {  } // I a ssume this is not possible

    add_shortcode( $shortcode, $function );
}
  • 1
    Hmm... Could you maybe add some examples or elaborate on what exactly are you trying to achieve? – Krzysiek Dróżdż Sep 1 '18 at 5:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.