Support

Account

Forum Replies Created

  • God! It´s a bit embarrassing when you get the answer seconds after posting the question. But instead of removing it, I´ll just leave it here as it might help someone else, just like arleym´s post helped me.

    Arleym was using a file field. I am using an image field. And I need it to be like that for reasons that go beyond this topic. (obs: wordpress does not support svg in the media library natively).

    Having said that, it wasn´t working because my image field was set to return the object array while it MUST be set to return the URL, instead.

    So the intial code on my previous comment was correct and after changing the value returned by the image field it now works!

    <?php $svgImg = get_field('my_custom_field', $term, 'option'); ?>
    <?php echo file_get_contents( $svgImg ); ?>

    Hope this may help somebody else.

  • I was looking for this exact answer! Thanks! However, I need to output the svg for each term in a taxonomy loop. When it comes to that, ACF requires the term variable to be passed on as a second parameter in get_field().

    So I tried this:

    <?php $svgImg = get_field('my_custom_field', $term, 'option'); ?>
    <?php echo file_get_contents( $svgImg ); ?>

    But I get this php error:

    “Warning: “file_get_contents() expects parameter 1 to be a valid path”

    Seems like it´s not an issue related to the order of the parameters as when I swap $term and option, it makes WP blind to what term I´m referring to:

    “Warning: file_get_contents(): Filename cannot be empty”

    $term has been properly defined as I have tested it with:

    <?php $svgImg = get_field('my_custom_field', $term); ?>
    <img src="<?php echo $svgImg['url']? />">

    This last piece of code works. But the previous doesn´t.

    Can somebody help?

Viewing 2 posts - 1 through 2 (of 2 total)