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?
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.
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????
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.
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?
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>';
At the end I have to publish my paret post to join it with child products.
There is no way to solve it.
Thanks!!!!