Tagged: acf, custom fields, shortcode
-
AuthorPosts
-
November 4, 2014 at 8:15 pm #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.
ThanksNovember 5, 2014 at 1:12 am #346284Hi 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.
November 5, 2014 at 10:48 pm #346816Thanks 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.
November 6, 2014 at 4:31 pm #347158Hey!
Please do so, they should have better insight on issues. Let us know if you have any other questions or issues
Cheers!
YigitOctober 31, 2017 at 5:27 pm #870897For 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.
November 1, 2017 at 11:47 am #871157March 24, 2023 at 10:37 am #1402271Hello 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.
March 25, 2023 at 12:13 pm #1402436 -
AuthorPosts
- You must be logged in to reply to this topic.