WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've developed invoicing system in WordPress for one of my website. I've used custom post type with custom meta field, integrated payment gateway to meet my needs. User generally generate invoice to upload fund. I've used a post submission from in frontend so that user can create an invoice by himself. Everything is running smoothly but one invoice created by an user is visible to other users. Ex. A created invoice, id: APL-2012110489586. User B can access the invoice by typing domin.com?invoice=APL-2012110489586. Now I want to restrict the invoice to be accessed from other user. Only admin and invoice creator can access the invoice. All users are in subscriber role. Need your guideline to perform this job.

share|improve this question
up vote 2 down vote accepted

In your Loop, whether for a 'single' page or an 'index' page, check the post author against the current user ID, and only display the post if they match. Assuming you are using a typical WordPress Loop, something like...

global $current_user;

// start of the Loop
if ( have_posts() ) {
     while ( have_posts() ) {
         if ($post->post_author != $current_user->ID) continue;

This also assumes that you are inserting your Custom Post Type entries correctly so that all of the data is populated as it should be.

share|improve this answer
Actually I want to display to admin and author. Anyway, got the point you mentioned. current_user_can('level_10') || ($post->post_author == $current_user->ID) can work for me. – Enthusiast Nov 4 '12 at 8:23

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.