0
votes

I need to add additional images next to post title, in this case decided to use ACF and add fields (image) into another plugin (Event Schedule). After I added fields in ACF I was trying to add some code from ACF documention however it doesnt work..

P.S. Every post will have different images based on their type. You can choose it while you are editing specific post.

In ACF field menu I chose to return format Image Array.

Tried with all return formats: Image Array, Image URL and Image ID. As I understand plugin cant find the variable acf_name and the image source is left blank.

<div class="wcs-class__meta">
<div class="wcs-class__inner-flex">
<h3 class="wcs-class__title"  :title="event.title" v-html="event.title"></h3> 

// Using this code from official ACF documentation

<?php 

$acf_name= get_field('acf_name');

if( !empty($acf_name) ): ?>

<img src="<?php echo $acf_name['url']; ?>" alt="<?php echo $acf_name['alt']; ?>" />

<?php endif; ?>

</div>
</div>

Now nothing happens, no errors, nothing. However, also it doesnt show those images I want.

1
Try using this : <?php echo get_field('acf_name', get_queried_object_id()); ?> - Kalrav Joshi
I assume $acf_name is false or empty. Few questions: your code assumes current post id exsists (in the loop) - if not, you must add it to get_field() Also double check ACF field name - Mulli

1 Answers

0
votes

Files in the plugins folder do not have access to global functions like get_field();. You can overwrite most plugin files in your theme, in which you should have access to global functions. Keep in mind that when the plugin you override gets updated, the file your are overriding will not. This could cause security issues.

The following article talks about the right ways of custmizing plugins: https://iandunn.name/2014/01/10/the-right-way-to-customize-a-wordpress-plugin/