I have too much data stored in custom fields which I don’t want to fetch on page-load, instead I’d give the user the opportunity to load the custom field values on click, possibly with ajax.
Is there a working way to do this?
I don’t have any code yet just the wp loop. I’m thinking about putting the custom field queries in a separate php file, but I have no idea how to make connection between single.php and the separate file. (loading the file with ajax is no problem.)
UPDATE:
I don’t need ajax, it’s just confusing me so far. I just want to display the custom fields associated with the post on a different page template. I think of it as if the custom fields would be “children” of a given post and clicking a link would load a page with just the custom fields on it.
Thanks.
I don’t know if you’ve found an answer on this question yet since it’s from 2011 but I have an idea on how to retrieve the data.
What if you created a VERY simple php file that took the post ID as a get variable and displayed the post’s custom fields?
It would look something like this:
This will create a table of name (Custom Field Name) and value (Custom Field Value). If you don’t want to use a table, of course you can format the internal bits however you want. I’m just trying to set you on the right track. Also, notice that there’s an
if
statement in there. I’m sure you don’t want to output the edit lock value or the last edit value.Now, on to how to get this information from the page:
First, you’ll need to create a button that will show the information.
And a box to show what you’re going to AJAX in:
You’ll want to make up some cool little jQuery goodness here.
And that should do it for you.
I know it was a bit long-winded, but I really wanted to cover all the bases. I hope this helped you out.