Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a shortcode that is built using a Thickbox form with various inputs that return the values. This works fine. However, I would like the existing values (if present) to re-populate the form if the user opens it again.

Here is an example of my shortcode:

[schema type="person" name="Andrew Norcross" description="I make interwebs" ]

I have a working jQuery match function to find the shortcode if it exists:

var code = $('div#wp-content-editor-container textarea').text().match(/\[schema(.*)\]/g);

the code above does get the entire shortcode as a string, but I'm at a loss for how to process it efficiently to get the values I want.

so what I want to accomplish:

  1. check for a specific part inside the shortcode data (i.e. name="Andrew Norcross")
  2. get the value inside the quotes and insert it into the field on the form

I've tried a few ways but nothing seems to function as expected.

share|improve this question

2 Answers 2

up vote 2 down vote accepted

Try something like this...

var code = $('div#wp-content-editor-container textarea').text().match(/\[(schema.*)\]/);
code = '<' + code[1] + '>';
alert($(code).attr('description'));​​​​
share|improve this answer
    
perfect! this is exactly what I wanted. –  Norcross Nov 2 '12 at 16:53

I would look into using jQuery's .data() function. Because its a shortcode, you can't really store values from the form into the 's data attributes and retrieve them that way, storing them with the .data() function seems like your best bet.

http://api.jquery.com/data/

share|improve this answer

Your Answer

 
discard

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.