Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

get an specific values for a specific key in custom fields WordPress

  • SOLVED

I have some custom fields on my wp.

If I use this function:


<?php

$custom_field_keys = get_post_custom_keys();
foreach ( $custom_field_keys as $key => $value ) {
$valuet = trim($value);
if ( '_' == $valuet{0} )
continue;
echo $key . " => " . $value . "<br />";
}
?>


I get this results:

2 => podcast_content
3 => seo_settings


And if I use this function:


<?php $item = get_post_meta($post->ID, 'podcast_content', $single = true) ?><br />
<?php echo print_r( $item ); ?>


I get this result:

Array ( [file] => Dave_McQueen_Mexico_Manufacturing_ Consultant.mp3 [length] => ) 1

So... I think I have two arrays ( file and length) inside the custom field podcast_content.

My question is... how can I get to display only one of the arrays... so it only display the file:

Dave_McQueen_Mexico_Manufacturing_ Consultant.mp3

Answers (3)

2012-09-07

Michael Caputo answers:

try this:

<?php $item = get_post_meta($post->ID, 'podcast_content', $single = true);
echo $item[file]; ?>


artrax57 comments:

this just work really nice. Thank you so much.

2012-09-07

Arnav Joy answers:

in place of

<?php $item = get_post_meta($post->ID, 'podcast_content', $single = true) ?><br />
<?php echo print_r( $item ); ?>

use this

<?php $item = get_post_meta($post->ID, 'podcast_content', $single = true) ?><br />
<?php echo $item ; ?>

2012-09-07

Martin Pham answers:

try this

<?php $item = get_post_meta($post->ID, 'podcast_content', $single = true);
echo $item['file'];
?>