This is my first time using ACF, and I’ve been getting on great with it – up to a point! I’ve got the pages all doing exactly what I want, but am using this plugin: https://wordpress.org/plugins/testimonial-rotator/ and can’t seem to get the get_field to print the details for this section. I am also having the same problem for the posts section of WordPress.
I have quite limited PHP knowledge at the moment, so am getting a bit confused with the documentation. I think that this how to: http://www.advancedcustomfields.com/resources/including-acf-in-a-plugin-theme/ should help me with my problem, but am not sure, as I am using a pre-existing plugin.
I really appreciate any help anyone can give me!
Code I am attempting to add in is:
<div class="<?php the_field('header_bullets_and_testimonials_colour'); ?>">
For the testimonials, and for the blog section it is
$image = get_field(‘featured_image’);
if( !empty($image) ): ?>
<img src=”<?php echo $image[‘url’]; ?>” alt=”<?php echo $image[‘alt’]; ?>” />
<?php endif; ?>`
Both of which are working on other parts of the same WP install.
Sorry – I’ve been having problems explaining it! I’ll do my best to break down what I am trying to do.
I’ve created a custom field type called testimonials, and set up a multiple choice for the specific colour.
I have set the custom field type to display on the testimonials rotator section for the plugin.
When you are in the testimonial rotator, you can choose which colour you want – so this part of the plugin is working fine.
Within the section that is printing the testimonials on each page – which is in the file loop-testimonial in the actual plugin, I have tried added the code as above, with in mind that it will print the chosen colour. This will then set the css class, which has been set in styling.
However, what I am getting when I do this is the following code printed:
<div class=".get_field('header_bullets_and_testimonials_colour');"> <div class="testimonial_rotator_quote"> Quote goes here.</div> </div>
The code I am inputting to the loop-testimonials.php file is
echo "<div class=\".get_field('header_bullets_and_testimonials_colour');\">\n"; echo "<div class=\"testimonial_rotator_quote\">\n"; echo ($show_size == "full") ? do_shortcode(nl2br(get_the_content(' '))) : get_the_excerpt(); echo "</div>\n"; echo "</div>\n";
I’m still confused. The plugin shouldn’t matter.
What does this mean, “I have set the custom field type to display on the testimonials rotator section for the plugin.”
Where do you have the field group set to display in the admin? ie: Where are you putting in your field values and saving?
Sorry – I’ve just been trying to work out how to explain it to you, but I can’t really. :\
The code you gave me worked, however I realised after putting it in that the variable was the wrong name. BUT it did manage to display the default value set in ACF for this variable. HOWEVER, when I changed the field name to the correct one, it went back to printing nothing.
How about this… what is your field group location set to?
Without seeing what you’re actually doing, it’s hard to really help. This code is kind of confusing to me.
echo ($show_size == "full") ? do_shortcode(nl2br(get_the_content(' '))) : get_the_excerpt();
Your above code doesn’t actually put the get_field() function into the content area, so you wouldn’t be seeing anything on the front end.
I’m not trying to print it on the front end – I’m trying to get it to print so that it reads as a div class.
The code you shared is from the testimonial plugin – I haven’t changed that at all – I just put it in so you could see part of it.
Might you be able to email me please: email@example.com as I would really appreciate you being able to take a proper look at it.
I have several different css classes set to call different backgrounds for the testimonials rotator depending on the page it is on.
I’ve set the custom field so the client can choose the right colour for each rotator / page.
The colour they choose is the name of the css class, so what I need it to do it print that name, so it can call the right css class.
Now we’re getting somewhere!
What is your field type? Are they choosing via radio buttons or select?
To get the value (not the name) of your radio/select, you just do it how I explained above:
echo '<div class="' . get_field('header_bullets_and_testimonials_colour') . '">';
Just make sure your field ‘Choices’ are setup to work as classes… so it would be:
class-one | Class One
class-two | Class Two
… as seen in the first image here: http://www.advancedcustomfields.com/resources/checkbox/
You must be logged in to reply to this topic.
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!
The ACF site is currently experiencing some issues.— Advanced Custom Fields (@wp_acf) September 29, 2022
We apologize for the inconvenience and we are working hard to get it back up and running as soon as possible.
© 2022 Advanced Custom Fields.