• Resolved dallashuggins

    (@dallashuggins)


    I’ve already created my custom select box (or dropdown) in functions.php (great tutorial here for those who are interested). Now I am looking to call the values I created in this select box, so I can create a function where every time someone selects one of the options in admin it automatically adds text to the front of the site. Does anyone know how to call values to the front end of wordpress based on the option selected in the select box? I’m not looking to add the dropdown to the front end, I just wanted to call text specific to each option.

    Been trying variations of the code below and it’s not working:

    <?php // adds custom dropdown field to front end
    $dropdown_values = get_post_meta( $post->ID, 'dropdown_select', true) ;
    $dropdown_ai_value = $field['id'];
    if( ! empty( $dropdown_values ) ) {
      echo $dropdown_ai_value;
    }
    ?>

    I’ve used the below code to pull in text values and it’s worked perfectly – how do you edit the code to be select box specific?

    <div class="mymetavaluekey1" style="font: Helvetica, Arial, sans-serif font-size: 18px font-style: italic text-align: center;">
    <?php  // adds custom title field to frontend
    $meta_values = get_post_meta( get_the_ID(), '_my_meta_value_key', true) ;
    if( ! empty( $meta_values ) ) {
      echo $meta_values;
    }
    ?>
    </div>

    Thank you!

Viewing 1 replies (of 1 total)
  • Thread Starter dallashuggins

    (@dallashuggins)

    Got it!

    <?php // adds custom value from dropdown to frontend
    $meta_values = get_post_meta( $post->ID, 'dropdown_select', true) ;
    if($meta_values == 'aivalue') { // 'aivalue' is the 'value' from my options array for the select box / dropdown
        echo __('<p>Your text here</p>');
    }
    else if($meta_values == 'manufacturing') {
        echo __('<p>Your text here</p>');
    }
    else if($meta_values== '3dprinting') { //
        echo __('<p>Your text here</p>');
    } 
    
    ?>
Viewing 1 replies (of 1 total)
  • The topic ‘Pulling content from dropdown menu onto front end of WordPress’ is closed to new replies.