0

the_meta is deprecated and it's told to replace it with get_post_meta. I'm using since long time this function for custom fields without styles: //the_meta function without styles:

function mymeta() {
if ( $keys = get_post_custom_keys() ) {

        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', "$key $value \n", $key, $value);
        }

    };

But I don't know how to replace it with get_post_meta (). I was using the mymeta function to list all the custom fields of a post for special purposes. And get_post_meta() retrieve just the value of a single custom field of a post.

The code where I use than "mymeta ()":

<?php $postslist = get_posts('numberposts=22&category_name=gigs&post_status=future&order=ASC&orderby=date'); foreach ($postslist as $post) : setup_postdata($post); ?><div> <h2 style=""><?php the_time('l \&\n\b\s\p\; j. F \'y');?><?php mymeta();?></h2> <h1><br /><?php the_title(); ?><br /></h1>

Any help welcome. thanx in advance & cheers

1 Answer 1

0

You can use get_metadata() to retrieve all meta data for a post, by leaving the third and fourth parameters empty.

$meta_key string Optional Metadata key. If not specified, retrieve all metadata for the specified object.

get_metadata( 'post', $post_id );
1
  • Thanx Caleb, but I didn't got it to work /replace it with get_metadata (). I use costum fields with several Names, and each post is using one of them with its own value.... In my case: starting time of a show and Value: the location with address
    – treibstoff
    Jun 30, 2023 at 17:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.