• Resolved lukelee

    (@lukelee)


    I am using Advanced Custom Field in WordPress. I use the_field(‘brand’) to display the value of custom field. In my case, it is called brand. However, when I use select field type, the result displayed twice. Like:
    nike:NIKE
    adidas:ADIDAS

    I assume one is label, one is value? how can I only show the value in frontend? I read the document, I modified my code, but received undefined error. below is my code, thank you for help:
    `$args = array(
    ‘post_type’ => ‘kosher’,
    $current_query[‘taxonomy’] => $taxonomy_term
    );

    $the_query = new WP_Query( $args );

    if ( have_posts() ) : while ( $the_query -> have_posts() ) : $the_query -> the_post(); ?>
    <?php
    $field = get_field_object(‘brand’);
    $value = get_field(‘brand’);
    $label = $field[‘choices’][ $value ];
    ?>
    <p><b><?php print_r($label); ?></b>  <?php the_field(‘key’); ?>  <?php the_title(); ?>  <?php the_field( ‘description’ ); ?> </p>
    <?php endwhile; else: ?>
    <p>There are no posts or pages here</p>`

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter lukelee

    (@lukelee)

    No one knows how to solve it? How does everyone use select fields?

    Thread Starter lukelee

    (@lukelee)

    I var_dump the object:

    $field = get_field_object('brand');
    var_dump($field);

    And below is what I have got, the value is herman jansen: HERMAN JANSEN, that’s what showed up on my front end every time, what code should I use to only show “HERMAN JANSEN”?

    array(17) {
    ["key"]=> string(19) "field_533221abdb3be"
    ["label"]=> string(5) "Brand"
    ["name"]=> string(5) "brand"
    ["_name"]=> string(5) "brand"
    ["type"]=> string(6) "select"
    ["order_no"]=> int(3)
    ["instructions"]=> string(0) ""
    ["required"]=> int(0)
    ["id"]=> string(15) "acf-field-brand"
    ["class"]=> string(6) "select"
    ["conditional_logic"]=> array(3) {
    	["status"]=> int(0)
    	["rules"]=> array(1) {
    		[0]=> array(2) {
    			["field"]=> string(4) "null"
    			 ["operator"]=> string(2) "==" } }
    		["allorany"]=> string(3) "all" }
    ["choices"]=> array(4) {
    	["BOLS"]=> string(4) "BOLS"
    	["HERMAN JANSEN"]=> string(13) "HERMAN JANSEN"
    	["WARNICKS"]=> string(9) "WARNICK'S"
    	["CARLTON BLACK"]=> string(13) "CARLTON BLACK" }
    ["default_value"]=> string(0) ""
    ["allow_null"]=> int(0)
    ["multiple"]=> int(0)
    ["field_group"]=> int(140)
    ["value"]=> string(28) "herman jansen: HERMAN JANSEN" }
    Thread Starter lukelee

    (@lukelee)

    I solved it. I went back and deleted the “brand” field, and recreated a “manufacture” field. then just copy&paste everything in there. then it works! really wield.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Advanced Custom Field not display select correctly’ is closed to new replies.