How to get several Custom Fields?

Asked

Viewed 37 times

0

How can I get the values of Custom Fields of different posts without need insert several get_post_meta(get_the_id(), 'key', true)?

2 answers

0

Use the function:

$custom_fields = get_post_custom($post->ID);

foreach ( $custom_fields as $key => $value ) {

echo $key . " => " . $value . "<br />";

}

0

You can search directly in the database:

global $wpdb;

$resultado = $wpdb->get_results( "SELECT id,meta_value from {$wpdb->postmeta} WHERE meta_key = 'key';" );

Browser other questions tagged

You are not signed in. Login or sign up in order to post.