Custom post status and preview

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:

Read More

You do not have permission to preview drafts.

EDIT 1

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.

Related posts

Leave a Reply

1 comment

  1. 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.