Support

Account

Home Forums Backend Issues (wp-admin) get_field not recognised

Solving

get_field not recognised

  • Hi all,

    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!

    Thanks,
    Rebecca

  • 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

    `<?php

    $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.

  • Are the custom fields on the ‘testimonial’ post type or somewhere else? Where are you adding the data? And on what page are you trying to display it?

    I’m not exactly following what you are trying to do.

  • 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";
  • Try this with the first line.. you shouldn’t be getting the actual get_field code in the HTML

    echo '<div class="' . get_field('header_bullets_and_testimonials_colour') . '">';

  • That has helped slightly – thank you! It’s shown me that it can print from the ACF, but it is just displaying the default value for that field – so could it be that because it is an external plugin, that it can’t see which page it is on?

  • 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.

  • I’ve tried changing that to quite a few things, but the one that I think is probably right is

    Post Type is equal to testimonial_rotator

  • 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: hello@rebeccashortseo.co.uk as I would really appreciate you being able to take a proper look at it.

  • Now i’m totally confused. The field is just there so you can choose a div class name for the slider?

  • 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/

  • Field type is select, although I have tried radio buttons too.

    It’s set up as you have shown, and still no luck. :\

  • Email me mike [at] thestizmedia.com

    Let me login if possible 😉

Viewing 18 posts - 1 through 18 (of 18 total)

You must be logged in to reply to this topic.