We have renamed Post Grid plugin to Post Grid Combohttps://pickplugins.com/rebranding-of-our-post-grid-plugin/

Call to advanced custom fields image object no longer working

We have renamed Post Grid plugin to Post Grid Combo
0
Call to advanced custom fields image object no longer working 1
Matthew
Oct 18, 2017 10:46 AM 1 Answers General
Member Since May 2016
Subscribed Subscribe Not subscribe
Flag(0)

In the layout editor, I have an HTML field, and in that field, I have the following:

<img src="[venue]" />

That shortcode is based on a function in my functions.php file that looks like this:

function post_grid_venue() {
$venue = get_field('venue_photo');
return $venue['sizes']['venue-thumb'];
}
add_shortcode('venue', 'post_grid_venue');

 

Of course, the function above is referencing an ACF image object. This was working fine for about a year now, and all of a sudden, not only does it not work anymore, but it crashes my entire site. All I get is a white screen when this function is active. Do you have any idea what might be causing this? Or is there a better way to call a specific image size into the layout editor?

2 Subscribers
Call to advanced custom fields image object no longer working 1
Call to advanced custom fields image object no longer working 3
Submit Answer
Please login to submit answer.
1 Answers
Sort By:
Best Answer
0
Call to advanced custom fields image object no longer working 4
PickPlugins
Oct 18, 2017
Flag(0)

Welcome to our forum.

Thanks for your trying, please try following code,

function post_grid_venue() {

  $post_id = get_the_id();

  $venue = get_field('venue_photo', $post_id);

  //var_dump($venue);

  //return '<img src="'.$venue.'" />'; // For Return Value: Image URL

  // For Return Value: Image Object
  // return $venue['sizes']['venue-thumb'];

  if(!empty($venue['sizes']['venue-thumb'])){
    return '<img src="'.$venue['sizes']['venue-thumb'].'" />';
    }else{
    return '';
    }

}
add_shortcode('venue', 'post_grid_venue');

Under the layout editor please use only following shortcode  [venue]

I hope this will solve your issue.

Regards

 

Call to advanced custom fields image object no longer working 5
PickPlugins
- Oct 19, 2017 10:04 AM
Flag (0)
0

I have tested the code with ACF plugin, Can you please send me a temporary admin access to your site?

Please make sure image filed is "venue-thumb" correct.

Regards

Call to advanced custom fields image object no longer working 6
Matthew
- Oct 18, 2017 11:55 PM
Flag (0)
0

I tried it, but it still didn't work. So I started removing pieces of the code, and I figured out that the following line is causing the hangup:

$venue = get_field('venue_photo');

The same applies to your line for setting the value for $venue. It's like the system doesn't recognize the image object. That being said, the image object is definitely there because I am using this same process to output a larger version of the image on the single page. I can't figure out why it's having trouble setting the variable through the function. And as I mentioned before, it has been working for over a year, and then suddenly it stopped.

I also tested this on another site that I am using the Post Grid plugin on, and it worked fine through the function. Do you think it is a theme issue?

Sign in to Reply
Replying as Submit