Comments on: WordPress – Adding custom fields to the post https://www.codexworld.com/wordpress-adding-custom-fields-to-the-post/ Web & Mobile App Development Company Tue, 14 Jul 2015 17:23:05 +0000 hourly 1 By: CodexWorld https://www.codexworld.com/wordpress-adding-custom-fields-to-the-post/comment-page-1/#comment-10351 Tue, 14 Jul 2015 17:23:05 +0000 https://www.codexworld.com/?p=473#comment-10351 In reply to Oshi.

Please check our Custom Shortcode tutorial from here – Create Custom Shortcode in WordPress

]]>
By: Oshi https://www.codexworld.com/wordpress-adding-custom-fields-to-the-post/comment-page-1/#comment-10269 Sun, 12 Jul 2015 15:43:46 +0000 https://www.codexworld.com/?p=473#comment-10269 Hey codexworld Thank you so much, that was a smooth respond you explain it so well that it seem so easy.

One last question. I want my product field to support a Shotcode so when i put a shortcode it works [myshortcode]

I’m not so sure where would i need to past this snap code ??
echo do_shortcode( get_post_meta( get_the_id(), ‘custom_field_key’, true ) );

Thank you

]]>
By: CodexWorld https://www.codexworld.com/wordpress-adding-custom-fields-to-the-post/comment-page-1/#comment-10268 Sun, 12 Jul 2015 14:08:06 +0000 https://www.codexworld.com/?p=473#comment-10268 In reply to oshi.

Thanks Oshi.
You should do the following modification at the above steps for adding radio buttons field into the custom meta box.
Step 2:
Add the radio buttons field array into the $custom_meta_fields variable like below.

// Custom meta fields array
$prefix 'custom_';
$custom_meta_fields = array(
    array(
        
'label'=> 'Gender',
        
'desc'  => 'Choose the author gender',
        
'id'    => $prefix.'author_gender',
        
'type'  => 'radio',
        
'options' => array(
            
'Male' => 'Male',
            
'Female' => 'Female'
        
)
    )
);

Add the radio buttons field HTML into the show_custom_meta_box() callback function. Into the switch statement add the following case.

// radio button field
case 'radio':
    foreach(
$field['options'] as $val=>$label):
        echo 
'<input type="radio" name="'.$field['id'].'" id="'.$field['id'].'" value="'.$val.'" ',$meta ' checked="checked"' '',' />
            <label for="'
.$field['id'].'">'.$label.'</label>&nbsp;';
    endforeach;
    echo 
'<br /><span class="description">'.$field['desc'].'</span>';
break;

Now you can see the radio buttons field into the Custom Meta section at the post add/edit page.
Step 4:
You need to use the below code for display the radio buttons value.

$post_author_gender $meta['custom_author_gender'][0];
echo 
'Gender: '.$post_author_gender
]]>
By: oshi https://www.codexworld.com/wordpress-adding-custom-fields-to-the-post/comment-page-1/#comment-10241 Sun, 12 Jul 2015 03:34:55 +0000 https://www.codexworld.com/?p=473#comment-10241 Hey thank you so much for you code after browsing and looking for a solution only your code it seem to work well.
My only question is if i had to add more field example a radio box on Step 2: Rendering Custom Meta Box, Would I need to add this on Step 3: Saving Custom Meta Data

]]>