0

i want to allow users to view their own pending posts in a front end page but when i access the links created for pending post in the database the links doesn't work until the post is approved enter image description here If I access the post GUID the one where the status is "publish" the link works, but the the one with the status "pending" does not.

I want to know what is the difference between a pending post and a published one other than their status so I can take those changes into account in order for the pending posts links to work for their authors only.

1

According to Wordpress Codex is a post status that awaits a user with the publish_posts capability (typically a user assigned the Editor role) to publish. (pending)

In other words, a post that is pending is a post that is not published meaning that it can not be viewed by not registered users with at least the publish_posts capability (Editor etc). So public users can not view the post. That's why the url is not "working".

The database just keeps the post status of the post. WordPress Core is responsible for handling the posts depending their status. Also I would suggest to not alter by no means the database manually and always use the WordPress API to modify WordPress elements like posts, pages etc

  • i actually want to view the pending post just by the author (current user) i don't want it to be viewed by any other user , is there's a way ? – ouqas mohamed Feb 14 '17 at 16:26
  • 1
    @ouqasmohamed Please edit your question to clarify what you're trying to do (ie, allow users to view their own pending posts in a front-end page). – Pat J Feb 14 '17 at 16:52
0

In database difference is just that — the different status in respective column.

The important difference is what that means — WP doesn't consider pending posts public, they won't show up in front end of the site and so on. Messing with this behavior usually goes quite poorly, status system is brittle and full of edge cases.

If you want to deal with items that are in the future (events for example) you should store that date information in post meta, separately from published dates.

If you want to just access pending post by an authorized user you can look into preview functionality, which is automatically exposed in editor for posts that hadn't been published yet.

  • do you mean the preview functionality from the dashboard ? i don't get it – ouqas mohamed Feb 14 '17 at 16:38
  • Yes, I do mean that. – Rarst Feb 14 '17 at 16:41
  • i know that i can preview it in the dashboard , i'm wondering if i can preview in the site just like any other post but it's visible only for the author – ouqas mohamed Feb 14 '17 at 16:49
  • Just take a preview link and try? There should be API function to retrieve it by code as far as I remember. – Rarst Feb 14 '17 at 17:01
  • the preview link created for the post in the database does not work with status is pending , but the same link works if the post is approved – ouqas mohamed Feb 14 '17 at 17:10
0

You could try this in your front end php:

    <?php if(is_user_logged_in()): ?>
     <?php $current_user = get_current_user_id(); ?>
       <?php query_posts('post_status=publish,draft&showposts=4&author='.$current_user);
?>
     <?php else: ?>
     <?php query_posts('post_status=publish&showposts=4'); ?>
     <?php endif; ?>
  • this is goona work for pending posts ? – ouqas mohamed Feb 15 '17 at 16:06
  • It should, if not change: <?php query_posts('post_status=publish,draft&showposts=4&author='.$current_user); ?> to <?php query_posts('post_status=publish,draft,pending&showposts=4&author='.$current_user); ?> – Heather Feb 15 '17 at 16:07
  • No problem, let me know how it goes. – Heather Feb 15 '17 at 16:09
  • it's not exactly what i need , what i need is to show the pending post in the front page that shows all other posts (published ) , this page already exist , the problem is im retrieving all pending and published post and im making a link on their title , but the links of the published ones works but for the pending ones does not it gives a 404 – ouqas mohamed Feb 15 '17 at 16:16
  • Can you give me an example of a link that gives a 404? I can actually preview my pending posts in the front end by clicking the Permalink within the Admin area of the post. – Heather Feb 15 '17 at 16:28
0

Use This Code to allow user can view pending post

function allow_pending_listings($qry) {
    if(is_user_logged_in()){
    $edit_data = get_post($_GET['eid']);    
     if (!is_admin() && $edit_data->post_author == $userdata->ID) {
    $qry->set('post_status', array('publish','pending'));
     }
    }
}
add_action('pre_get_posts','allow_pending_listings');

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.