Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

i use use this code to set slider in header with CF, how i can disable when CF is empty or set another CF key to exclude it?

<?php
  $custom_fields = get_post_custom($post_id);//Current post id
  $my_custom_field = $custom_fields['slider_id'];//key name
  foreach ( $my_custom_field as $key => $value )
  echo get_new_royalslider($value) ;
?>
share|improve this question

1 Answer 1

up vote 0 down vote accepted

Less code lines with get_post_custom_values()

$values = get_post_custom_values('slider_id', $post_id);

// if non-empty
if($values) {
    foreach($values as $value)
        echo get_new_royalslider($value);
}

If $values array is empty, nothing happens.

share|improve this answer
    
thanks Max and sorry for my english, your code it's ok and run, i add "else" for original slider, because in category or post_custom of my theme i don't have custom_field!! and i don't know how activate this!! $values = get_post_custom_values('slider_id', $post_id); // if non-empty if($values) { foreach($values as $value) echo get_new_royalslider($value); } else { echo tfuse_header_content('header');} tnks a lot!!!! are you super –  sam80it Feb 2 '13 at 16:38
    
sam80it, if everything is OK, please accept the answer to make it "answered" so other people can easily find it. –  Max Yudin Feb 2 '13 at 16:51
1  
ok i accepted your answer as answer, if not corret tell me how i can do –  sam80it Feb 2 '13 at 16:55
    
@sam80it, check How does accepting an answer work? –  brasofilo Feb 2 '13 at 17:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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