Skip Navigation

[Resolved] Show all post status

This support ticket is created 6 years, 6 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 6 replies, has 2 voices.

Last updated by oriolc 6 years, 6 months ago.

Assisted by: Christian Cox.

Author
Posts
#579694

I close a topic: https://toolset.com/forums/topic/custom-post-join-with-a-product/ that Noman solutions me, but now I have an small problem.
He creates a custom select, but I want to know if it is possible to see all the post status (draft, published and pending) created by the users.
Now it appears only the published posts?
There is a way?

#579701

Sure, try modifying the arguments passed into get_posts like this:

function current_user_parent_post_select_func(){
    $current_user = wp_get_current_user();
    $userid = $current_user->ID;

    $args = array(
        'post_type' => 'post', // parent post slug
        'author' => $userid,
        'post_status' => array('publish', 'pending', 'draft', 'auto-draft', 'future', 'private', 'inherit', 'trash'),
        'posts_per_page' => -1
    );
    // Return an array of all posts of current user
    $user_posts_list = get_posts($args);

    $content = '<select name="event_parent" class="form-control" output="bootstrap" required="required">';
    $content .= '<option>--- Choose your add ---</option>';

    foreach ($user_posts_list as $post) :
      $content .='<option value=' . $post->ID . '>' . $post->post_name . '</option>';
    endforeach;
    $content .='</select>';
    wp_reset_postdata();
    return $content;
}
add_shortcode( 'current_user_parent_post_select', 'current_user_parent_post_select_func' );

You can remove any statuses from the post_status array that you do not want to include.

#579761

Thankyou,
Just one thing,
Now it appears published, draft... but in post status 'pending' the post name doesn't appear.
That is because until it is not published is not inserted in database and his title can't be obtained????

#579908

Hi, I noticed a bug in the code I provided earlier that was causing the author filter to be ignored. I have updated the code above to reflect that change, so please update your code as well. Regarding the missing post name, this code is designed to show the Post slug here, and I'm not sure of any reason why the Post slug would be unavailable. If this is still happening after the update I mentioned, then please verify that the posts in question have a slug assigned. If so, then please let me know if this is happening for all User roles, or just a specific User role.

#580325

First of all, sorry about my English!!!
I made changes but Draft or Pending Posts doesn't appears.
I think that could be because they don't have a specific slug assigned.
Example: -Published: hidden link
-Draft (for Pending is the same type of URL): hidden link
Another thing that my post type have is that I have Rewrite permalinks to make it more SEO friendly. That can be a problem too?

#580366

If there's no slug defined yet, what would you like to display instead? The post ID could be used with this update to the foreach loop code:

$content .='<option value=' . $post->ID . '>' . $post->post_name ? $post->post_name : $post->ID . '</option>';
#583261

At the end I have to publish my paret post to join it with child products.
There is no way to solve it.
Thanks!!!!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.