-
AuthorPosts
-
May 23, 2016 at 5:44 pm #636984
HI, I am trying to get ‘advanced custom fields (ACF)’ to work with enfold. In particular, the posts shortcodes from the avia editor. In other words, when choosing to show blog posts with the template builder in grid format, I want to pull in extra data from my posts from ACF.
I have been unsuccesfully editing the childtheme/shortcodes/postslider.php file, I can get some of the data but it seems to just repeat itself rather than getting the individual posts values.
I have been intouch with plugin support for ACF and they have said:
It seems that the
global $post;
method is not working for your case.The problem is the
get_field()
function doesn’t know the right post for each excerpt. To fix it, you need to pass the ID of the post. Could you please ask the theme author how to get the ID of the post when you use the “avf_post_slider_entry_excerpt” hook? Is it possible that the ID is passed in the $entry variable?…. can anyone help out with this?
May 23, 2016 at 11:50 pm #637169Hey dannhanks,
The easiest way to get the post ID is by opening the post in admin dashboard
There are several other methods please check https://premium.wpmudev.org/blog/display-wordpress-post-page-ids/
Best regards,
VinayMay 23, 2016 at 11:55 pm #637178hi, thanks Vinay but you have misunderstood. Its to do with the loop in:
childtheme/shortcodes/postslider.phpI am trying to get ACF’s custom fields to work dynamically in the above file.
thanks
May 25, 2016 at 5:40 pm #638162Hi, to save any further confusion:
May 26, 2016 at 5:10 am #638444Hi,
Thank you for the info. Something like this should work:
function avf_post_slider_entry_excerpt_func($excerpt, $prepare_excerpt, $permalink, $entry ) { $field = get_field('fieldname', $entry->ID); // do something to the $field return $excerpt; } add_filter('avf_post_slider_entry_excerpt', 'avf_post_slider_entry_excerpt_func', 10, 4);
Best regards,
IsmaelMay 27, 2016 at 12:07 pm #639233HI,
I have added this in place in my postslider.php file so my code now looks like this:$markup = avia_markup_helper(array('context' => 'entry_content','echo'=>false, 'id'=>$the_id, 'custom_markup'=>$custom_markup)); $excerpt = apply_filters( 'avf_post_slider_entry_excerpt', $excerpt, $prepare_excerpt, $permalink, $entry ); $output .= !empty($excerpt) ? "<div class='slide-entry-excerpt entry-content' $markup>".$excerpt."</div>" : ""; // addition as advised above function avf_post_slider_entry_excerpt_func($excerpt, $prepare_excerpt, $permalink, $entry ) { $field = get_field('excerpt', $entry->ID); // do something to the $field return $excerpt; } add_filter('avf_post_slider_entry_excerpt', 'avf_post_slider_entry_excerpt_func', 10, 4); // end of addition as advised above $output .= "</div>";
… this broke the site saying error message:
Fatal error: Cannot redeclare avf_post_slider_entry_excerpt_func() (previously declared in /public_html/wp-content/themes/childtheme/shortcodes/postslider.php:453) in /public_html/wp-content/themes/childtheme/shortcodes/postslider.php on line 453
Any ideas?
thanks!May 28, 2016 at 5:21 am #639661Hi,
That code should go in the functions.php file, not in the postslider.php file. It’s a filter for the post excerpt. What is the name of the custom field that you’re trying to add?
Best regards,
IsmaelMay 31, 2016 at 10:51 am #640807hi, there are a few I need to add onto this page but one of them is called excerpt.
May 31, 2016 at 10:57 am #640813Hi,
You can use this function to get
the_excerpt
:
https://codex.wordpress.org/Function_Reference/get_the_excerptBest regards,
JosueMay 31, 2016 at 11:08 am #640822Hi, I tried adding the text to the functions file and nothing happend, no extra content on the post-slider.
thanksJune 1, 2016 at 5:10 am #641198Hey!
Please post the login details here so that we can check the name of the custom fields. And while you’re on it, please check if the following code does anything:
function avf_post_slider_entry_excerpt_func($excerpt, $prepare_excerpt, $permalink, $entry ) { $field = get_field('excerpt', $entry->ID); // do something to the $field $excerpt = $field . $excerpt; return $excerpt; } add_filter('avf_post_slider_entry_excerpt', 'avf_post_slider_entry_excerpt_func', 10, 4);
Cheers!
IsmaelJune 2, 2016 at 12:45 pm #642009Hi Ismael,
I finally got to the bottom of this, in the postslider.php file, I needed to add the code:
$output .= get_field('field-name', $entry->ID);
Thanks for your help!
Dann
-
AuthorPosts
- The topic ‘how to get the ID of the post when you use the “avf_post_slider_entry_excerpt”’ is closed to new replies.