Skip to content
Advertisement

Trying to get the Mail Poet list in a select

I am trying to get mail poet list in a dropdown using the code below but i am only getting first value and id in option, although there are 5 lists available, what am i doing wrong?

    $mplistname = array(MailPoetAPIAPI::MP('v1')->getLists()[0]['name']);
    $mplistid = array(MailPoetAPIAPI::MP('v1')->getLists()[0]['id']);
    $mplistoptions = array_combine($mplistid, $mplistname);

    foreach($mplistoptions as $key=>$value) {
            $mplistoptions[$key] = $value;
    }

Advertisement

Answer

As Patryk said, don’t make two API calls when one suffices.

And you are getting only the first name and id, because you are accessing only the first entry in both your arrays … that’s what [0] does.

This should probably just be condensed to something like this:

$data = MailPoetAPIAPI::MP('v1')->getLists();

foreach($data as $record) {
    // do stuff with $record['name'] and $record['id'] here
}
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement