How to Add Radio Button to Post or Page in WordPress

In our previous discussion, we already made a clear conception of meta box and also learned how to add custom text field to any page/post type.

Today we will discuss same thing but instead of text field we will show how to add radio button for any post type. The all functional process are same but need to changes the HTML format & added function for update the meta box.

Again we check the function which will work for us to create a meta box in admin panel.

add_meta_box( $id, $title, $callback, $post_type, $context,$priority, $callback_args );

So now we add this function to admin for administrative interface. Let say we would like to get user input where user will select for whom the post is going to be published. To be developed we can create three input field with radio button.

So here is the example:

That’s all. If you refresh your post type page, you can see this mata box added under the rich area. Now question how to get this value in template. There are two functions for this:

Function 1: $meta_values = get_post_meta( $post_id, $key, $single );

Function 2: $custom_fields = get_post_custom($post->ID);

So if use first function, we can call it from inside the loop :

But if we use second function, we have to get all meta values for this post id 1st then get the specific meta values:

So that’s all. Hope there is no confusion to get this meta value through meta boxes.Still if you have any further question feel free to drop a message here. We will response in our shortest period.
Thanks.

This post has already been read 4773 times!

Mehedi Hasan

Cool WordPress Developer having much agile experience to develop any kind of WordPress sites & plugins. Also good in troubleshooting, fixing & making any kind of tweaks for WP site.

More Posts

Mehedi Hasan

Cool WordPress Developer having much agile experience to develop any kind of WordPress sites & plugins. Also good in troubleshooting, fixing & making any kind of tweaks for WP site.

2 thoughts on “How to Add Radio Button to Post or Page in WordPress

  • December 23, 2014 at 4:54 am
    Permalink

    hai sir I am start to learn php and wordpress. can u help me do one things? I want to do add radio button for category list in front end view.

    Reply
    • December 23, 2014 at 7:02 pm
      Permalink

      Hi, Would you please contact for support here as your query doesn’t seem to related with this post.
      Thanks.

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *