AUSSERTECH.labz // DAS_WORKSHOP >>> Little Fix for WordPress’ “the_meta()”

Yesterday i discovered a little “bug” in WordPress’ “the_meta()” function: It would output an empty list if there are no Custom Fields, which led to some unwanted space between elements on some of my articles. I did some research (aka Google) and found a solution on the WordPress forums, which was a modification of the original “the_meta()”.

I do not want to touch WordPress’ core files, so i developed a solution which worked similarily to what i had found, but could be called from a template file (“single.php” in my case):

$keys = get_post_custom_keys(); foreach ( $keys as $value ) { $first = $value{0}; if ( $first != '_' ) { echo '<div class="post-meta">'; the_meta(); echo '</div>'; break; } }

So this thing reads the Custom Keys from a post and checks them one by one in a loop. There are several keys used by the system, which all start with an underscore (“_”). Custom Fields are not allowed to have this char at the beginning, and that is what we are looking for. In case of a hit (i.e. a key without an underscore at the beginning) it will break the foreach loop and output “the_meta()” (i added a div around it to style it as a block element). If nothing is found, it will output nothing. Simple as that.

Schlagwörter: , , ,

Hinterlasse eine Antwort

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind markiert *

Du kannst folgende HTML-Tags benutzen: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>