‘get_post_meta’ value condition not going through

I am trying to display some code depending on a custom field in wordpress.

This code works

Read More
<?php // ALP displays bottom only if specified in post options 
$display_bottom = get_post_meta( get_the_ID(), 'wpcf-post-block', true );
// Check if the custom field has a value.
if ( $display_bottom == 1 ) {
// inludes bottom if specified in post options
include( get_stylesheet_directory() . '/partials/bottom.php'); 
} ?>

This simplier piece of code should do the same, but it does not display anything althouugh the meta value equals 1.
It seems the condition for the value is not met / not properly defined.

<?php if ( get_post_meta( $post_id, 'wpcf-post-block', true ) == '1' ) { 
include( get_stylesheet_directory() . '/partials/bottom.php'); 
}?>     

Related posts

Leave a Reply

1 comment

  1. Try this — You must need to get the ID then assign it to $post_id variable and you are good to go

    <?php
    $post_id = get_the_ID();
     if ( get_post_meta( $post_id, 'wpcf-post-block', true ) == '1' ) { 
    include( get_stylesheet_directory() . '/partials/bottom.php'); 
    }?>