0

I have created custom post type and created the post in a front custom form using logged in user and set status 'pending'. Now I want to show my created post preview like the published post.

I have hit URL like admin http://localhost/project/?post_type=deals&p=3305

but it is working for admin, not for author user.

In Another way, we can say that how to show pending custom post for the author only for preview.

my code--->>

'public' => true,'publicly_queryable' => true,'show_ui' => true, 

Please help

2 Answers 2

0

If you do get_permalink($post_id), you should get the preview link. I did the same for my site. The author should be able to see this unless some specific filters are in place which prevent this.

On the post itself, I use this to show it's pending.

if ( get_post_status( $post_id ) == 'pending' ) {
    echo '<div class="site__notice uppercase">This is a preview. This profile has not been approved yet.</div>';
}

Can you share some code or provide some more info ?

5
  • get_permalinks($post_id); is getting url localhost/project/?post_type=deals&p=3305 but not working, it is working for admin Feb 24, 2018 at 3:58
  • Does it work if you add &preview=true to the link ?
    – Beee
    Feb 24, 2018 at 5:20
  • yes i have tried but not working Feb 24, 2018 at 8:36
  • Have you tried deactivating all plugins and setting a default theme ? This is 'anti-default' behaviour afaik, so something must be blocking it.
    – Beee
    Feb 24, 2018 at 12:14
  • Without you showing the code or making it 'live' it's hard to determine the issue
    – Beee
    Feb 24, 2018 at 12:18
0

It Works after below code added in functions.php

function preview_draft_posts($query) {

  if ( is_admin() || get_query_var('suppress_filters') )
    return $query;


  $query->set('post_status', array('publish', 'pending', 'draft'));


  return $query;

}

if(isset($_GET['p']) && isset($_GET['post_type']) && ($_GET['post_type'] == 'deals' || $_GET['post_type'] == 'events')&& get_current_user_id() > 0){
    global $wpdb;
    $deal_posts = $wpdb->prefix . 'posts';
    $sql_claim ="SELECT ID FROM $deal_posts WHERE ID='".$_GET['p']."' AND post_author=".get_current_user_id();
    $myrows = $wpdb->get_row( $sql_claim, ARRAY_A );
    if(isset($myrows['ID']) ){

         add_filter('pre_get_posts', 'preview_draft_posts');
    }

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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