I have a custom field, called “The_Date”. This custom field can be available in all posts, one or more times. So I use a script to get the informations from the custom fields off all posts.
After a while I found out that the “do_shortcode” of my custom field slow down my page really hard. This happend, if I load more then 10 custom fields from the same type at one page. Is wordpress firing to much php/js requests?
Thats my code:
<?php
// all meta value for "The Date"
$pos = get_unique_post_meta_values('the_date', 'post');
if($pos){
foreach( $pos as $position){
// run javascript inside custom field
$position = do_shortcode( $position );
echo $position . "n";
}
}
?>
How can I fix this?
I’d recommend getting the relevant information from ‘The_Date’ field inside the Loop and adding it as an HTML-Entity (e.g. attribute, tag-content, whichever makes more sense in your case).
This should avoid DB-Lookups.
In case you store the Date in a “human readable” format and use the JavaScript for sorting, then i’d recommend switching to UNIX-Timestamps and only converting to a readable format upon display.