1

This worked perfectly in a previous version of wordpress, different site tho. I have a custom field called flash on several wp pages but it keeps defaulting to "printed if results are empty". Any ideas on why this wouldn't work?

<?php 
if ( function_exists('get_post_custom_values') ) 
  {    
   $mykey_values = get_post_custom_values('flash');
   if(count($mykey_values) > 0)
    {

foreach ( $mykey_values as $key => $value ) 
 { 
  echo "$value";


 }
    }
   else
    {
     //printed if results are empty
   echo("mainPage.swf");
    } 

  } 
 else
  {
   //printed if function doesn't exist
   echo("mainPage.swf");
  }
?>
2
  • As a test, try specifying a post ID that you know has this custom field populated: get_post_custom_values('flash', $known_post_id); Commented Jul 19, 2010 at 13:41
  • agreed with Pat, the API considers the post id as required; or it'll default to post id = 0 and you'll get zero content. Commented Jul 20, 2010 at 3:54

1 Answer 1

1

Hi not really sure why that is not working (as long as you are sure you do have custom fields with 'flash' values in the post). Anyhow, try the following, I am sure the following will work.

<?php
  $custom_fields = get_post_custom();
  $my_custom_field = $custom_fields['flash'];
  foreach ( $my_custom_field as $key => $value )
    echo $key . " => " . $value . "<br />";
?>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.