I am using wordpress 3.4 (the last before 3.5) and I have declared a post status type, and a custom user role called agent. It is for a custom post type, property.

  register_post_status( 'purchased', array(
      'label' => _x( 'Purchased', 'post' ),
      'public' => false,
      'exclude_from_search' => true,
      'show_in_admin_all_list' => true,
      'show_in_admin_status_list' => true,
      'label_count'               => _n_noop( 'Purchased <span class="count">(%s)</span>', 'Purchased <span class="count">(%s)</span>' ),
  ) );

My problem is that I don't want to show publicly those, (thus public=false ) but when I try to preview them with my user (in admin) it says:

You do not have permission to preview drafts.


My code for preview is this:

$nonce = wp_create_nonce('post_preview_' . $post->ID);
$url = esc_url(add_query_arg(array( 'preview' => 'true', 'preview_id' => $post->ID, 'preview_nonce' => $nonce), get_permalink($post->ID)));
$previewUrl = "<a href=\"" . $url . "\" class=\"btn btn-info btn-mini\" target=\"wp-preview\" title=\"" . esc_attr(sprintf(__('Preview %s'), get_the_title())) . "\" rel=\"permalink\">" . __('Preview') . "</a>";

Kudos to Jesse for noticing the error, but, now when I go to the preview link i get a 404 error (not found). With public = true this doesn't happen but it falls back to DO NOT SHOW category.

  • what does the preview url look like? does it have preview_id and preview_nonce params?
    – Jesse
    Apr 8 '13 at 9:24
  • I checked your code but its working for me. Explain it more briefly like how you are saving it like draft or pending review etc... Apr 8 '13 at 9:27
  • yes. I have used this code :$nonce = wp_create_nonce('post_preview_' . $page->ID); $url = esc_url(add_query_arg(array( 'preview' => 'true', 'preview_id' => $id, 'preview_nonce' => $nonce ), get_permalink($page->ID))); and linked the $url in an <a>..</a> (note $page refers to the post type object)
    – Panagiotis
    Apr 8 '13 at 9:28
  • 1
    'preview_id' => $id and get_permalink($page->ID) , can you see the difference?
    – Jesse
    Apr 8 '13 at 9:33
  • @VinodDalvi I am using a custom administration which takes the post after the "agent" has paid with paypal and updates it with status "purchased"
    – Panagiotis
    Apr 8 '13 at 9:54

So actually everything were more simpler, as long as someone (namely me) would have looked how "draft" post status works.

Apparently there are a lot of variables that wordpress codex does not reveal / has documented, such as the following:

register_post_status('purchased', array(
    /* 'label' => _x( 'Purchased', 'post' ),
      'public' => false,
      'exclude_from_search' => true,
      'show_in_admin_all_list' => true,
      'show_in_admin_status_list' => true,
      'label_count'               => _n_noop( 'Purchased <span class="count">(%s)</span>', 'Purchased <span class="count">(%s)</span>' ), */
    'label' => _x('Purchased', 'post'),
    'protected' => true,
    '_builtin' => true, /* internal use only. */
    'label_count' => _n_noop('Purchased <span class="count">(%s)</span>', 'Purchased <span class="count">(%s)</span>'),**

I took the code from "draft" (which in fact we all know it works) and duplicated it for my custom post status. Therefore, it is now visible to the owner, but invisible to the others (on the frontend). Once it gets published, it works just fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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