Search code examples
phpwordpressmetadatacustom-fields

Wordpress meta data is written on top of page instead of the loop


i'm building a wordpress webpage based on the Skeleton Wordpress theme.

I have 2 posts showing on a page and each of these posts have custom fields values (meta data). Im using the shortcode from the skeleton theme to get a post-feed from a specific category and in that loop i have inserted this tag that displays the custom fields data

<?php the_meta(); ?>

I am getting the data - but the problem is, the data is shown on TOP of the page instead of inside the in the post.

What could've ive possibly done wrong? or is it something with skeleton i am doing wrong?

Webpage : http://visbyfangelse.se.preview.binero.se/rum-priser-preview/

as you can see two posts are shown - and the meta data is shown on the top of the page.

Code to the loop : http://pastebin.com/mRQY5GNz As you can see i want the meta displayed in the div which i assigned this class to "my_room_meta".


Solution

  • the_meta() echos the results to the page, you could make your own replacement function:

    function get_the_meta() {
            if ( $keys = get_post_custom_keys() ) {
                    $output="<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,', ');
                            $output.= apply_filters('the_meta_key', "<li><span class='post-meta-key'>$key:</span> $value</li>\n", $key, $value);
                    }
                    return $output . "</ul>\n";
            }
    }
    }