Hi I hope someone can help me. I have a site that has WooCommerce installed and a plugin to filter the products. Upon activation of this plugin ( http://goo.gl/nZzicU ) ACF reports this error
Warning: Illegal string offset ‘url’ in /Applications/AMPPS/www/ClientName/wp-content/themes/ThemeName-2015/woocommerce/content-product_cat.php on line 68
along with others all relating to calls to ACF.
Example …
$image = get_field(‘logo’, ‘option’);
$url = $image[‘url’];
Then doing this …
<?php
echo ‘
'; print_r( $url ); echo '
‘;
?>
Returns 5
not the expected url of the uploaded image.
It seems to happening to all ACF calls.
I know this is to do with the product filter plugin, but I have had no help from the developer about this at this time and I’m going mad with this.
Thanks
Is your image field set to return the image ID, Object or url?
That should work, the only things that would prevent from working are
1) The field is returning false, meaning that an image has not been added for the field.
2) Another plugin is interfering with ACF
I looked at the free version of the plugin you mentioned and there doesn’t seem to be anything in it that should cause a problem, but there might be something in the paid premium version that might.
If you deactivate this plugin other plugin does the error go away?
Yeah, deactivation of the plugin allows ACF to work again. As I say I don’t think the issue lays with ACF, but the other plugin, but I wondered if there was something that someone could point me at to help.
I’ve tried installing the free version of this plugin on a test site that I use for testing WooCommerce and ACF. I’m not seeing an issue. This is probably something specific to the premium version.
So what you really need to see is what is being returned? and why?
You can try
$image = get_field('logo', 'option');
print_r($image);
This is what I have before I activate the filter plugin…
Array
(
[ID] => 5711
[id] => 5711
[title] => client-name-logo-blue
[filename] => client-name-logo-blue1.png
[url] => http://localhost.com/client-name/wp-content/uploads/2015/03/client-name-logo-blue1.png
[alt] =>
[author] => 1
[description] =>
[caption] =>
[name] => client-name-logo-blue
[date] => 2015-03-06 17:14:25
[modified] => 2015-03-06 17:14:25
[mime_type] => image/png
[type] => image
[icon] => http://localhost.com/client-name/wp-includes/images/media/default.png
[width] => 447
[height] => 160
[sizes] => Array
(
[thumbnail] => http://localhost.com/client-name/wp-content/uploads/2015/03/client-name-logo-blue1-150×150.png
[thumbnail-width] => 150
[thumbnail-height] => 150
[medium] => http://localhost.com/client-name/wp-content/uploads/2015/03/client-name-logo-blue1-300×107.png
[medium-width] => 300
[medium-height] => 107
[large] => http://localhost.com/client-name/wp-content/uploads/2015/03/client-name-logo-blue1.png
[large-width] => 447
[large-height] => 160
[yith-woocompare-image] => http://localhost.com/client-name/wp-content/uploads/2015/03/client-name-logo-blue1-220×154.png
[yith-woocompare-image-width] => 220
[yith-woocompare-image-height] => 154
[logo-image-size] => http://localhost.com/client-name/wp-content/uploads/2015/03/client-name-logo-blue1-447×160.png
[logo-image-size-width] => 447
[logo-image-size-height] => 160
[paralax-image-size] => http://localhost.com/client-name/wp-content/uploads/2015/03/client-name-logo-blue1.png
[paralax-image-size-width] => 447
[paralax-image-size-height] => 160
[team-image-size] => http://localhost.com/client-name/wp-content/uploads/2015/03/client-name-logo-blue1-400×143.png
[team-image-size-width] => 400
[team-image-size-height] => 143
[shop_thumbnail] => http://localhost.com/client-name/wp-content/uploads/2015/03/client-name-logo-blue1-170×114.png
[shop_thumbnail-width] => 170
[shop_thumbnail-height] => 114
[shop_catalog] => http://localhost.com/client-name/wp-content/uploads/2015/03/client-name-logo-blue1-341×160.png
[shop_catalog-width] => 341
[shop_catalog-height] => 160
[shop_single] => http://localhost.com/client-name/wp-content/uploads/2015/03/client-name-logo-blue1.png
[shop_single-width] => 447
[shop_single-height] => 160
[mpfy_location_tag] => http://localhost.com/client-name/wp-content/uploads/2015/03/client-name-logo-blue1.png
[mpfy_location_tag-width] => 31
[mpfy_location_tag-height] => 11
)
)
After plugin activation
5711
It’s as if the plugin is causing ACF to behave as if you have the field set to return the image ID rather than an image array.
Well, I can help you with a hack, but not finding the cause of or fixing the incompatibility. I’m afraid that fixing it will take several hours of debugging.
Here is a hack to try, no guarantee it will work though
$image = get_field('logo', 'option');
if (!is_array($image)) {
$image = acf_get_attachment($image);
}
$url = $image['url'];
To get this fixed properly, you should probably contact the plugin author for the filter plugin. You might get a run-a-round unless you can point to a bug in their code though.
You can also thy submitting a new ticket here http://support.advancedcustomfields.com/new-ticket/. The ACF support staff may be able to help you, but that I can’t say. I only help out here of the forum.
Thanks! That has worked like a charm.
I’ve tried getting the plugin author to help, but he seems to take the position of the problem isn’t my code.
@hube2 Thanks once again for your help, but I have noticed another ‘bug’ the Wysiwyg Editor fields don’t seem to be displaying content with paragraph tags anymore either with the activation of the filter plugin.
I currently have the call looking like this …
the_field(‘column_1′, $term);
// $term = $taxonomy.’_’.$term_id to get the correct category content
I found this http://goo.gl/Y8Jw5E and tried reversing it like this …
the_field(‘column_1’, true, true, $term);
But that broke it 🙁
but I tried this and it worked …
$wysiwyg = get_field('column_1', $term);
echo apply_filters('the_content', $wysiwyg);
I hope this may help others in the future.
That other plugin is definitely interfering with the operation of ACF. I know that it can be hard to get some plugin authors to correct things. I’m not sure it will get you anywhere but if you put in a ticket on this to the ACF support maybe they can work out the problem and work with the other plugin developer to resolve the issue. http://support.advancedcustomfields.com/new-ticket/, it might be worth a try.
@hube2 Hi man! How would I solve the same problem for an gallery field?
I use
<?PHP if(get_field('fotos')) : $images = get_field('fotos'); ?>
<img src="<?php echo $images[0][sizes][home]; ?>" alt="" />
<?PHP endif; ?>
And [08-Aug-2017 16:29:17 UTC] PHP Warning: Illegal string offset ‘home’ in
In my case, I use a File type with file as the field name and it produces an illegal string offset. So after changing it to file_upload as the new field name it solved my issue.
Randy
The topic ‘Illegal string offset’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.