In wordpress is there any way that I can get the value of a custom field in jQuery?
Leave a Reply
You must be logged in to post a comment.
In wordpress is there any way that I can get the value of a custom field in jQuery?
You must be logged in to post a comment.
this should do the trick:
it hooks into the wordpress head, checks to see if the current post or page has a custom field called my_custom_field_name, if it does it spits out a var in java script that can then be used by jquery anywhere else.
It’s tested and works.
Custom field values are stored in your database, therefore, you can’t access them via jQuery unless you’ve made it available to the resulting HTML markup somehow.
If you’re thinking of using custom field values in your jQuery/JS, I’d go about it by modifying my theme to actually spout the values I need directly on the markup. You could use hidden
INPUT
fields for that, or maybe even flushing the values directly on some script.