Support

Account

Home Forums General Issues Select Field Labels.

Solving

Select Field Labels.

  • Is there an issue with displaying the select field labels right now? I’ve done this many times but for some reason today it’s not working. It’s just echoing no content. Below is my code.

    <?php if( get_field(‘breed’) ): ?>
    <?php
    $field = get_field_object(‘breed’);
    $value = get_field(‘breed’);
    $label = $field[‘choices’][ $value ];
    ?>
    <p><span class=”epd-label”>Breed:</span> <?php echo $label; ?></p>

  • Hi @tellstevens

    That’s weird. I’ve just tested it on the latest version of ACF PRO and it is working great. Could you please var_dump() the $field and $value variables like this:

    $field = get_field_object(β€˜breed’);
    $value = get_field(β€˜breed’);
    
    echo "<pre>";
    
    var_dump($field);
    echo "============";
    var_dump($value);
    
    echo "</pre>";

    Please let me know the result. Thanks πŸ™‚

  • Thanks, I stuck it in the top of this page http://demo.cedarridgegenetics.com/boar/bistro/ It looks like it is working because it’s kicking out yorkshire which is correct. I’m also using that field as a meta-key to sort the boars by breed on the sires page and it works there.

  • Hi @tellstevens

    It seems that you used a text field instead of a select field:

    ["type"]=>
      string(4) "text"

    Please make sure that you have set the “Field Type” to “Select” and set the “Choices” option with the choices you want. I’ve attached a screenshot for your reference.

    Thanks πŸ™‚

  • See attachment. It is setup as a select field.

  • Hi @tellstevens

    It seems you have another field group with the same name (breed) registered via PHP. You can see that the page returned a field object with “field_breed” as the key. Could you please check your template and remove that code? This page should give you more idea about it: https://www.advancedcustomfields.com/resources/register-fields-via-php/.

    I hope this clears things up πŸ™‚

  • Hmmm…I don’t seen another custom field with that same title. I have 5 different field groups. All of the other groups have 1 field and they’re not breed. I had double checked my boar field group because that was my first thought but there is nothing duplicated there. See screenshots. I’ve never registered fields using the functions.php but just to be sure I double checked there and I just have a custom header in there. I even did a find all on the entire site folder and the only other place I use that field is as a meta_key for the boars on the full listing page. I’m not sure where else to look.

  • Hi @tellstevens

    That’s weird. Maybe the code is placed in the file of your theme or plugins. Could you please try to reproduce the issue on one of the WordPress’ stock themes (like Twenty Sixteen) with other plugins deactivated? If it disappears, then you can activate the theme and plugins one by one to see which one causes the issue.

    If the issue disappeared when you changed the theme, then it means that the code is registered in your theme. I suggest you run a text search (field_breed) by using a search tool. There are several tools that can do it: http://stackoverflow.com/questions/317944/tools-to-search-for-strings-inside-files-without-indexing.

    Thanks πŸ™‚

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

The topic ‘Select Field Labels.’ is closed to new replies.