php – Open access to posts in WordPress based on Category query-ThrowExceptions

Exception or error:

I have the following code on my single.php and page.php files in wordpress

        $key = 'Free Story';
        $themeta = get_post_meta($post->ID, $key, TRUE);
        if($themeta != '') {
        $free_story = 1; 

    <?php if($_SESSION['auth'] == '1' OR current_user_can( 'write_post' ) OR $free_story == '1' ) { ?>  

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>

    <div class="post" id="post_<?php the_ID(); ?>">

    <span id="map"><a href="<?php echo get_option('home'); ?>/"><?php _e('Home','arthemia');?></a> &raquo; <?php the_title(); ?></span>

    <h2 class="title"><?php the_title(); ?></h2>

        <div class="entry" style="padding-top:15px;">
        <?php the_content(__('<p>Read the rest of this page &raquo;</p>','arthemia')); ?>

        <?php wp_link_pages(array('before' => __('<p><strong>Pages:</strong>','arthemia'), 'after' => '</p>', 'next_or_number' => 'number')); ?>



    <?php endwhile; endif; ?>

    <?php } else { ?>

        <div class='panel panel-default' style='margin-top:10px;'> <div class='panel-heading' style='background:#0079BD; color:#fff; text-align:center;'>Subscribe To The Journal</div><div class='panel-body'>  <p style='text-align:center'>
        If you are already registered with The Journal/, please <a href='' class=class='SumaPostContent'><b class="text-danger"> click here </b></a> to log in and continue reading. If not, <a href=''><b class="text-danger"> please click here for subscription options </b>. </a>.</p></div></div>

    <?php } ?>

Near the top there is this snippet:

<?php if($_SESSION['auth'] == '1' OR current_user_can( 'write_post' ) OR $free_story == '1' ) { ?>

Basically, if my javascript auth query is 1, OR the current user can write posts OR a CUSTOM FIELD called Free Story has a value of 1, the page loads completely for the reader. IF none of those are true, they get a notice to log in or to subscribe.

I’d like to not use a Custom Field for Free Story. I’d like to create a WP category called Free Story and have PHP check if the post or page it is trying to load is a member of the Free Story category.

Where do I start with this?

Thanks for pointers!

How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *