0

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.

2

Try something like this...

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

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/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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