WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to grab data from my theme options and have to use them in meta option fields in custom post types. I know how to grab theme option data and show them on front pages but don't know how to grab it for backend usage. I want to use data from one of my theme options text field and put it into my metabox text field.

Actually I have two check boxes on my metabox text field and also two metabox text fields above that text field. Also two text fields in my theme options in which I have to put some html and javascript code. So here is my code:

Metabox text fields and checkboxes:

<input type="textarea" id="c" value="Your Name" />
<input type="textarea" id="d" value="My Name" />
<input type="checkbox" id="a" />
<input type="checkbox" id="b" />
<input type="textarea" id="e" />

Theme Option Text fields:

<input type="textarea" id="f"  />
<input type="textarea" id="g"  />

I have to put javascript in theme option text fields somewhat like this:

<script type=text/javascript> name: 'My Name is/', name2: 'Your name is/', </script> 

Now comes the real worry. I want that when I click check box with the id 'a', the code from the theme options text field with the id 'f' will be put into the metabox text field with the id 'e' but with little modification. The modification i need is that the data from metabox text fields with the id 'c' and 'd' will first be added to the code that has been grabbed from the theme option text field with the id 'f' in such a way that value of metabox text field with the id 'c' is added to the "name: My Name is/(Here will be the value of text field with the id 'c')" and value of metabox text field with the id 'd' is added to the "name2: Your Name is/(Here will be the value of text field with the id 'd')".

I am also using jquery code for these checkboxes behaviour. Here is my jQuery code.

$(function () {
$('#a, #b').change(function () {
    var $a = $('#a'), $b = $('#b'), $c = $('#c');
    if (this.id == 'a' && this.checked) {
       $c.val('Hello World!');
       $b.prop('checked', false);
    } else if (this.id == 'b' && this.checked) {
       $c.val('Not hello World!'); 
       $a.prop('checked', false);
    } else {

​ Obviously there is flaw in this jQuery code as I don't want these values such as Hello world or Not Hello World of my metabox text field with the id 'c'. I want the value of that field as I explained earlier. Please help me in this regard. I am very much frustrated.

share|improve this question
You grab the data the same as you do for the Front End – Bainternet Oct 3 '12 at 18:36
Your question is very vague. You grab the options data in the exact same way on both front and back-ends. Are you trying to ask how to create a metabox? – helgatheviking Oct 3 '12 at 18:37
Well please let me clarify it a bit. I want to use data from one of my theme options text field and put it into my metabox text field. Don't know how to do it. Please help me. Thanks – user1666698 Oct 3 '12 at 19:50

Hope this help.

Use WPAlchemy to set up your metaboxes. http://www.farinspace.com/wpalchemy-metabox/. So far it is the easiest way to do it, IMHO. Afteryou setup your <input type="text"> field just add <?php echo get_option('your option name')?> with a conditional to check if it already has a value.

Untested code :

        $value = $metabox->get_the_value('_coordinate');
    } else {
        $value = get_option('your option name');
<input type="text" name="<?php $metabox->the_name('_coordinate'); ?>" value="<?php echo $value; ?>"/>
share|improve this answer
Thanks for your response. Please check the updated question as I have edited it to clarify a bit what I really needed. Please answer it. – user1666698 Oct 4 '12 at 6:19

You can use the get_option function on the back-end too. There are several possibilities on how to pass your option value to your script:

  1. Use wp_localize_script function to pass PHP values to your script (see WordPress Codex page for this function).
  2. Print your option value along with name and name2 values inside a script tag.
  3. Use AJAX. When user clicks your checkbox A, you send an AJAX request to the server requesting the value of your option.

The rest is just a matter of joining all the pieces together and putting them inside your textfield using jQuery.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.