PHP Conditional Issue

I have a small problem. And I am not sure why am I getting this problem. See what I did was I limited a page to “Public Member” and I want this page to be access Library members too because library members would have access to all pages. So what I did was I added a simple condition like this:

if ( $user_role == "library-Member"  && $pageLevel == "public-member" ) {
    $displayPost = "true";
}

And in my post I added this condition

Read More
if ( $displayPost == "true" ) {
   .. execute html stuff ..
}
else {
   wp_redirect( 'http://sample.org/restricted-area' );
   exit;
} 

But somehow the condition is not working. I have also checking var_dump($displayPost) the output is true

Can someone help me please? Thanks.

EDIT

Image Samples:
1. Sample 1
2. Sample 2

CODE:

<?php
global $current_user;
$user_roles = $current_user->roles;     
$user_role = array_shift($user_roles);  
if ( !is_user_logged_in() ) { $user_role =  array( 'public-member' ); }

$pageLevel = get_post_meta( $post->ID, 'user_type', true );

if ( $user_role == "library-Member"  && $pageLevel == "public-member" ) {
    $displayPost = "true";
}

if ( $displayPost == "true" ) {
?>
<div class="main wrap cf">

    <div class="row">
        <div class="col-8 main-content">

            <?php if (have_posts()): the_post(); endif; // load the page ?>

            <div id="post-<?php the_ID(); ?>" <?php post_class('page-content'); ?>>

            <?php if (Bunyad::posts()->meta('page_title') != 'no'): ?>

                <header class="post-header">                

                <?php if (has_post_thumbnail()): ?>
                    <div class="featured">
                        <a href="<?php $url = wp_get_attachment_image_src(get_post_thumbnail_id(), 'full'); echo $url[0]; ?>" title="<?php the_title_attribute(); ?>">

                        <?php if ((!in_the_loop() && Bunyad::posts()->meta('layout_style') == 'full') OR Bunyad::core()->get_sidebar() == 'none'): // largest images - no sidebar? ?>

                            <?php the_post_thumbnail('main-full', array('title' => strip_tags(get_the_title()))); ?>

                        <?php else: ?>

                            <?php the_post_thumbnail('main-slider', array('title' => strip_tags(get_the_title()))); ?>

                        <?php endif; ?>

                        </a>
                    </div>
                <?php endif; ?>

                    <h1 class="main-heading">
                        <?php the_title(); ?>
                    </h1>
                </header><!-- .post-header -->

            <?php endif; ?>


            <?php Bunyad::posts()->the_content(); ?>


            </div>

        </div>

        <?php Bunyad::core()->theme_sidebar(); ?>

    </div> <!-- .row -->
</div> <!-- .main -->
<?php
} else {
    wp_redirect( 'http://sample.org/restricted-area' );
    exit;
} 
?>

Related posts

Leave a Reply