how to visible post only for posted user and admin

  • Unknown's avatar

    Hi have way that one category’s post visible only for posted user and admin . I have a custom post status ,extra category and custom post template for this . I want to visible this category’s post only for posted user and admin . Please give me a good solution : I write a code on my template but it doesn’t work .

    <?php
    /**
     * The template for cat 2 single posts.
    
     */
    
    get_header(); ?>
    <?php
              $user_id = the_author_meta('ID');
              $admin_ch = get_user_by('id', 1);
              $cu_user = get_current_user_id();
    
          if($cu_user == $user_id || $cu_user == $admin_ch) {
             while ( have_posts() ) : the_post(); ?>
              
    " >
    ', '' ); ?> '; the_post_thumbnail('screenr-blog-list'); echo '
    '; } } ?> </header><!-- .entry-header --> </div> <!-- .entry-meta -->
    →' ), the_title( '"', '"', false ) ) ); wp_link_pages( array( 'before' => '', ) ); ?> </div><!-- .entry-content --> <?php show_publish_button(); ?> </article><!-- #post-## --> </div> <?php endwhile; // End of the loop. } else { echo "You can't show this"; } ?> <?php get_footer(); ?>
  • Hi there,
    You submitted the same question to Expert support via https://wordpress.com/help/contact at the same time as posting here. Please don’t post requests in multiple places, as that makes it more difficult to provide support to everyone effectively.

    You’re posting some code for a new template, and adding a template is not a feature for WordPress.com. If your site is hosted here, you cannot add this.

    If you are using this on a self-hosted site on another host, we will want to direct you to support for your site. This support forum is only for WordPress.com sites.

    WordPress.com and WordPress.org are a little separate, and that can be confusing. https://en.support.wordpress.com/com-vs-org/

    On that other support request, I asked for you to share the site URL to better direct you to the help you need. Can you please share your site address?

  • The topic ‘how to visible post only for posted user and admin’ is closed to new replies.