Viewing 2 replies - 1 through 2 (of 2 total)
  • The function the_meta() isn’t meant to return anything, it always displays the meta keys, even if you put it inside if().
    So on this line of your script
    <?php if(the_meta()): ?>
    the custom fields are always displayed, the_meta returns NULL, the condition evaluates to false and the execution hops to these lines

    <?php else: ?>
    
        <div id="portfolio-meta">
        <p id="projmeta-head-negative">This item has no information associated with it. Sorry.</p>
    			</div>
    
    			<?php endif; ?>

    and displays the message “This is no information…”

    The part of the script between if and else is never executed.

    There is a little function that should do what you want

    $post_meta_keys = get_post_custom_keys($post->ID) ;
    $nonprotected_meta_keys = 0;
    foreach ( $post_meta_keys as $key ) {
        if( is_protected_meta($key)){
                continue;
            }
            else $nonprotected_meta_keys++;
        }
    if($nonprotected_meta_keys > 0) :
    the_meta();
    else : ?>
            <p>No meta here!</p>
        <?php endif;

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘PHP if statement for custom fields.’ is closed to new replies.