0

So I can't seem to figure this out, so I'm reaching out to see if someone might be able to help me.

I've tried to include as many details as possible if it makes sense, so please let me know if I'm missing something before downvoting.

I have the following method:

function instagram_posts(): bool|string
{
    if (!function_exists('is_plugin_active')) {
        include_once(ABSPATH . 'wp-admin/includes/plugin.php');
    }
    if (!is_plugin_active('fh-instagram/autoload.php')) {
        return false;
    }
    if (empty($items = Instagram::get_items_for_api(50))) {
        return false;
    }
    var_dump($items);

    var_dump(json_encode($items));

    return json_encode($items);
}

var_dump($items); gives me the following output:

array(50) {
  [0]=>
  object(Plugin\Instagram\Item)#976 (7) {
    ["id":"Plugin\Instagram\Item":private]=>
  }
  [1]=>
  object(Plugin\Instagram\Item)#1030 (7) {
    ["id":"Plugin\Instagram\Item":private]=>
    string(17) "17842233125750202"
  }
}

When I run var_dump(json_encode($items)); I get the following output:

string(151) "[{},{}]"

How can I convert my array of objects so that it can transform it to json and then use it within Postman? This is what it currently looks like in Postman:

array(50) {
  [0]=>
  object(Plugin\Instagram\Item)#973 (7) {
    ["id":"Plugin\Instagram\Item":private]=>
    string(17) "17992874035441353"
  }
  [1]=>
  object(Plugin\Instagram\Item)#1027 (7) {
    ["id":"Plugin\Instagram\Item":private]=>
    string(17) "17842233125750202"
  }
}

It should be outputted such as:

[
  {"id": etc..}
]

All help will be appreciated!

0

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.