• Hey all, I am trying to return the custom value from my meta box select option array (excuse me for improper terminology). My current code is returning the first option value (ivory_homes) whereas I need it to return the proper name (Ivory Homes).

    Please see my code snippets below. Any help is appreciated!

    My meta box:

    // Builder Name
    		array(
    			'name'		=> __('Builder Name'),
    			'id'		=> "builder",
    			'type'		=> 'select',
    			'options'	=> array(
    				'ivory_homes'		=> __('Ivory Homes'),
    				'liberty_homes'		=> __('Liberty Homes'),
    				'rainey_homes'		=> __('Rainey Homes')
    			),
    			'std'		=> array( '' ),
    			'desc'		=> __('Choose from the following options.')
    		),

    …and my php call:

    <?php 
    
    $builder = get_post_meta($post->ID, 'builder', true);
    									if(!empty($builder))
    									{
    										?>
    									<strong><?php echo $builder; ?></strong>
    
    										<?php
    									}
    
    									?>

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter aronjeney

    (@aronjeney)

    Can anyone help me with this? I am still struggling to call the proper option value from my selected meta key. Any help is greatly appreciated!

    I think it is returning the proper option value. The option value in the generated select menu is ‘ivory_homes’, the ‘Ivory Homes’ part is just what’s displayed. Try this:

    array(
    			'name'		=> __('Builder Name'),
    			'id'		=> "builder",
    			'type'		=> 'select',
    			'options'	=> array(
    				'Ivory Homes'		=> __('Ivory Homes'),
    				'Liberty Homes'		=> __('Liberty Homes'),
    				'Rainey Homes'		=> __('Rainey Homes')
    			),
    			'std'		=> array( '' ),
    			'desc'		=> __('Choose from the following options.')
    		),

    Thread Starter aronjeney

    (@aronjeney)

    Hey Andrew, thanks for the reply. I have tried that before and although that does work I am filtering by builder in another page of my site and when I list the homes as their names (without the underscores) they add spaces to my URL (creating %20), causing issues with the filter. I wonder if this is in fact the route I need to go and find a jquery or something that will allow me to strip the spaces from the url. Any ideas as to how I do that? Thanks again for your help so far!

    Sure. You could do it in php instead of js in your template file or something. Try stripping out the underscores and replace them with spaces and capitalize the first letter of each word.

    <?php
    $val = 'ivory_homes'
    $final_val = ucwords(str_replace('_',' ',$val));
    ?>

    Thread Starter aronjeney

    (@aronjeney)

    OK thanks, I will give that a try. thanks for your help so far!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Return custom value from get_post_meta’ is closed to new replies.