Home › Forums › Front-end Issues › ACF with enfold theme
I am trying to get ACF working with enfold theme. I can get it to work in certain parts but in others I am getting no luck – I have tried support at enfold buth they directed me here.
My issue is on one of the post loops – the one that shows the product grid this file is postslider.php
This file is coded in a different way to what I am used to, output looks similar to this:
$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>" : "";
$output .= "</div>";
I can get the custom field showing with the following code:
$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>" : "";
$output .= get_field('excerpt');
$output .= "</div>";
note the addition of:
$output .= get_field('excerpt');
but its loading the same info for every post – its just a repetition of one of the post’s custom fields and is not loading the individual items details.
Does anyone know if I missing something here?
thanks!
Hi @dannhanks
The get_field() function needs the post ID to be passed as the second parameter if you call it outside The Loop. It should be something like this:
get_field('excerpt', 99);
Where ’99’ is the ID of your post. There’re several ways to get the post ID outside The Loop. One of them is by using the post global variable like this:
global $post;
$post_ID = $post->ID;
Then you can use it for the get_field() function like this:
get_field('excerpt', $post_ID);
I hope this helps 🙂
Hi James, thanks for getting back – I have had a chance to have a look at this but I am still getting the repetition.
I may be getting myself confused here but I think the code I added before was already in the loop.
Have a look at the attached screenshot for clarification:
You will see 3 posts returned through the theme code, each with a unique title/image/excerpt (in the grey box). You will then see underneath the field I am attempting to include from ACF which is a manual exerpt. Even though these are unique for each post, its just repeating the first post’s one.
Thanks for looking into it!
Dann
Hi @dannhanks
Could you please debug some variables for me? Please try this code and let me know the result:
global $post;
$post_ID = $post->ID;
echo "<pre>";
echo "=== post id ===\n";
var_dump($post_ID);
echo "=== repetaer without id ===\n";
get_field('excerpt');
echo "=== repetaer with id ===\n";
get_field('excerpt', $post_ID);
echo "</pre>";
Thanks 🙂
Hi James,
that output:
=== post id ===
int(135)
=== repetaer without id ===
=== repetaer with id ===
4 times at the very top of the page above all the content but below the header.
<div id="main" data-scroll-offset="0">
<pre>=== post id === int(135) === repetaer without id === === repetaer with id === </pre>
<pre>=== post id === int(135) === repetaer without id === === repetaer with id === </pre>
<pre>=== post id === int(135) === repetaer without id === === repetaer with id === </pre>
<pre>=== post id === int(135) === repetaer without id === === repetaer with id === </pre>
<div id="prodtitle"...etc
… was the html output
Hi @dannhanks
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?
Thanks!
hi, I am in talks with the theme author – trying different methods out, have a check of:
… see if there is anything there you can pickup?
Hi @dannhanks
Great! With that information, I think we can do some further tests.
The “Cannot redeclare avf_post_slider_entry_excerpt_func()” was showing up because you have another function with the same name. Could you please check it out? Maybe you can use different function name?
Also, could you please try the following code?
echo "<pre>";
echo "=== post id ===\n";
var_dump($entry->ID);
echo "=== repetaer with id ===\n";
echo get_field('excerpt', $entry->ID);
echo "</pre>";
Thanks 🙂
Hi James,
the above code when put where I needed it to go added:
=== post id ===
int(181)
=== repetaer with id ===
Compact, Portable Explosion-Proof Light
ATEX Zone 1, 2, 21, 22
36W and 55W
IP66/67
above all content.
🙂
Sorry – I just noticed I was looking at a page with only 1 result on – on a page with several posts this has returned all the results but again, its threw it to the top of the screen, not where I have placed it in the code.
Cracked it!!
$output .= get_field('excerpt', $entry->ID);
…was the code I was looking for!
Wow! That was epic!
Thanks for your support!
The topic ‘ACF with enfold theme’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.