Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #346071

    Hello,

    I have created some custom fields using ACF and have managed to get these to display as I want by adding this code to the relevant single post templates:

    <?php the_field('field_name'); ?>

    However, I also want to be able to display the contents of a custom field in the Post Slider, so that it is visible when added as a shortcode in the advanced layout editor.

    I understand that I need to modify the template file enfold/config-templatebuilder/avia-shortcodes/contentslider.php
    The contents of the field should appear above the excerpt, so I’m assuming the relevant code needs to go around line 375, before:

    if($show_meta && !empty($excerpt))

    But at this point I get stuck! Can anyone advise me please? Any help much appreciated.
    Thanks

    #346284

    Hi kifela!

    Add this to line 420,

    $output .= the_field('field_name');
    

    I’m not sure if that function echoes or returns. If it returns then your good but if it echoes then it’s going to display outside of the content slider. There is probably a PHP trick out there for that but I do not know of it. You’ll want to contact the plugin author in that case or use get_post_meta, http://codex.wordpress.org/Function_Reference/get_post_meta.

    Best regards,
    Elliott

    • This reply was modified 10 years ago by Elliott.
    #346816

    Thanks Elliott. I tried that, not sure if it’s echoing but I don’t see the custom field displayed anywhere. I might try to take this up with the author of ACF and see if I have any luck there.

    #347158

    Hey!

    Please do so, they should have better insight on issues. Let us know if you have any other questions or issues

    Cheers!
    Yigit

    #870897

    For anyone landing here, this is achieved by:

    $output .= get_field('field_name', $entry->ID);

    or if you want to use the if statement, stop/start the php with:

    ?>
    <?php if( get_field('field_name', $entry->ID) ): 
    					$output .= get_field('field_name', $entry->ID);
     endif; ?>
    <?php 
    • This reply was modified 7 years ago by dannhanks.
    #871157

    Hi,

    Thanks a lot for sharing, much appreciated :-)

    Best regards,
    Rikard

    #1402271

    Hello everyone,
    I added this string to my post slider.php:

    $output .= get_field('field_name', $entry->ID);

    But it prints “array” on the website.
    How can I fix?

    Furthermore I would like to embed this variable in a div.
    Can someone help me?

    Best,
    Marco

    • This reply was modified 1 year, 7 months ago by marcomila.
    #1402436

    Hi Marco,

    Then you would likely have to specify which part of the array that you want to display, you can refer to the ACF documentation for clarification. We can’t help with that unfortunately.

    Best regards,
    Rikard

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.