• Resolved zanyojimbo

    (@zanyojimbo)


    Hi everyone,
    thanks as usual for the awesome plugin (literaly!). I saw your custom fields article, but I did not get how it is possible to populate a dynamic dropdown with the result of a database query, and not with pre-set values in the back-end.

    Any link to existing material or advice is greatly appreciated

    Thanks a lot
    Matteo

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author awesomesupport

    (@awesomesupport)

    Hi:

    Unfortunately, we don’t have anything built-in that handles custom queries – all we have built-in are the taxonomy drop-downs.

    You would have to write all your own php code to handle this. You can use any of the action hooks in themes/submission.php to execute your query and render the drop-down. You have hooks in that file before and after most fields so you can render your customer query drop-down just about anywhere on the form.

    I hope this helps.

    Thread Starter zanyojimbo

    (@zanyojimbo)

    Hi, thanks for the answer. I tried to use my own code but I have some issues in understanding where to hook it. Since I want to recover the data dynamically from the DB, but that is different to each logged-in user (I need to use wp_get_current_user()), I think hooking to “plugins_loaded” as in your custom fields guide is not the way, as it will not distinguish each user. I tried hooking to “wpas_get_custom_fields” (as in the code below), but though it seems to work better still it does not seem to find “wpas_add_custom_field” (I have an alert sent if the code enters the “If” part and it doesn’t). Any suggestion on the hook and on how to make the code find “wpas_add_custom_field” (even removing the “if” the code does not work, obviously)?

    Thanks a lot

    Reference code:
    add_action( ‘wpas_get_custom_fields‘, ‘wpas_user_custom_fields’ );
    function wpas_user_custom_fields() {

    if ( function_exists( ‘wpas_add_custom_field’ ) ) {

    //My code to get SQL data (which works)

    wpas_add_custom_field( ‘myname’, $array_from_SQL);
    return;
    }
    }
    }

    Thread Starter zanyojimbo

    (@zanyojimbo)

    To add to my comment, I also tried to copy/paste the code on your custom fields article but it does not seem to show any additional custom field in my forms (using the “plugins_loaded” hook)… not sure what I am doing wrong

    Plugin Author awesomesupport

    (@awesomesupport)

    Hi – can you tell me which custom fields article you copied and pasted from?

    Thanks.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Dynamic dropdown from DB’ is closed to new replies.