0

I have this loop that works fine but I have to check if the custom fields of the post objects ("houses") have content. I try this with "isset" and nothing happens. Tried "isset", too but same problem.

$args2 = array (
    'numberposts' => -1,
    'post_type'   => 'houses'
);
$custom_posts2 = get_posts($args2);
foreach ( $custom_posts2 as $custom_post2 ) {

// check here if custom post type opjects custom field "sz_website" has content
if ( !empty ($custom_post2->post_website)) {
    echo '<div class="wpcf7-list-item-field">' . $custom_post2->sz_website . '</div>';
} else { 
    echo "do nothing"; 
}

}
wp_reset_postdata();
  • You have custom field (metabox) or you have custom column in the DB table wp_posts? – Shibi Dec 21 '17 at 9:12
0

Try this:

$args2 = array (
    'numberposts' => -1,
    'post_type'   => 'houses'
);
$custom_posts2 = get_posts($args2);
foreach ( $custom_posts2 as $custom_post2 ) {

// check here if custom post type opjects custom field "sz_website" has content
$sz_website = get_post_meta( $custom_post2->ID, 'sz_website', true );

    if ( !empty ($sz_website)) {
        echo '<div class="wpcf7-list-item-field">' . $sz_website . '</div>';
    } else { 
        echo "do nothing"; 
    }

}
wp_reset_postdata();

Let me know if helps.

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.