I need to make an accordion from arbitrary fields the_meta(); . But the standard call creates markup of this type:

 <ul class='post-meta'> <li><span class='post-meta-key'>your_key:</span> your_value</li> <li><span class='post-meta-key'>your_key:</span> your_value</li> </ul> 

That is, your_value not highlighted by any tag that does not suit me. The very output of the the_meta(); function the_meta(); implemented in the file wp-includes/post-template.php

 function the_meta() { if ( $keys = get_post_custom_keys() ) { echo "<ul class='post-meta'>\n"; foreach ( (array) $keys as $key ) { $keyt = trim($key); if ( is_protected_meta( $keyt, 'post' ) ) continue; $values = array_map('trim', get_post_custom_values($key)); $value = implode($values,', '); echo apply_filters( 'the_meta_key', "<li><span class='post-meta-key'>$key:</span> $value</li>\n", $key, $value ); } echo "</ul>\n"; } } 

Edit this file also does not fit, so that when you upgrade does not fly away.

How to add a filter or action to wrap your_value in a span or p ?

    2 answers 2

    And if you try differently for example

     <ul> <?php $custom_fields = get_post_meta($post->ID,'',false); foreach ( $custom_fields as $key => $value ){ $theValue = $value[0]; $i=$key; echo "<li><span class='post-meta-key'>".$key ."</span><span class='post-meta-value'>" . $theValue . "</span></li>"; }?> </ul> 
    • That's right, but the _edit_last, _edit_lock, _thumbnail_id outputs to the array as well. I do not understand why ... - Yuri Rymar
    • @Yury Rymar you didn’t write that it wasn’t necessary to output this way I solved this problem <pre> switch ($ i) {case $ i! = Preg_match ('/ _ /', $ key): break; case $ i == '/ * here you also add unnecessary meta fields * /': break; default: echo "<tr> <td>". $ key. "</ td> <td>". $ theValue. "</ td> </ tr>"; break; } </ pre> instead of echo in your example. - Sergalas
    • <pre> clean only :). - Sergalas

    Use get_post_custom_keys(); , and create a wrapper yourself.

    • Try to write more detailed answers. Explain what is the basis of your statement? - Nicolas Chabanovsky