is there any error in following code? when i use following code in content.php file of my theme, then nothing is displayed on blog, it seems there is some error. and when i comment folowing code everything gets back to normal.

<?php if (empty(get_custom_field_value("signature",""))) : ?>
    <?php the_category( '<span>/</span>' ); ?>      
<?php endif; ?>

here is get_custom_field_value function:

function get_custom_field_value($szKey, $prefix = '', $bPrint = false) {
    global $post;
    $szValue = get_post_meta($post->ID, $szKey, true);
    if ( $bPrint == false ) return (empty($szValue) ? "" : $prefix . $szValue); else echo (empty($szValue) ? $szValue : $prefix . $szValue);

empty will only take variables passed by reference. so empty(some_function()) will never work. See the php docs for more information.

<?php if (get_custom_field_value("signature","")) : ?>
    <?php the_category( '<span>/</span>' ); ?>      
<?php endif; ?>

You're better off just checking for the boolean, like above. The get_custom_field_value function already takes care of making sure you get something back.

On a side note: you should prefix your function names. get_custom_field_value is very generic. yourtheme_get_custom_field_value (replacing "yourtheme" with the theme name) has less of a chance of conflicting with other function names.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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