Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Warning: Illegal string offset 'id' [duplicate]

Tags:

php

I have defined two variables as follows:

$pic = get_tax_meta($books->term_id,'books_field_id', true);
$imageurl = wp_get_attachment_image_src( $pic[id], 'list-thumb' );

print_r($pic) results in the following:

Array ( [id] => 302 [src] => http://localhost/mysite/wp-content/uploads/2013/10/apic.jpg )

However, I get the following warning from $pic[id]:

Warning: Illegal string offset 'id'

Any idea what I'm doing wrong?

like image 649
user1444027 Avatar asked Sep 20 '25 02:09

user1444027


1 Answers

This seems to have fixed the problem:

$pic = get_tax_meta($books->term_id,'books_field_id', true);
if (isset($pic['id'])) {
      $picid = $pic['id'];
};
$imageurl = wp_get_attachment_image_src( $picid, 'list-thumb' );
like image 119
user1444027 Avatar answered Sep 21 '25 20:09

user1444027