How to display deleted post in MB Frontend Submission Dashboard (Trash Section)
Support › MB Frontend Submission › How to display deleted post in MB Frontend Submission Dashboard (Trash Section)
- This topic has 4 replies, 2 voices, and was last updated 2 years ago by
Way Leong.
-
AuthorPosts
-
April 11, 2023 at 12:06 PM #41422
Way Leong
ParticipantHi,
I would like to display the posts that have been deleted by the user via MB Frontend Submission Dashboard. What is the workaround? Because MB Frontend Submission Dashboard did not have that feature available.
April 11, 2023 at 7:24 PM #41433Peter
ModeratorHello,
If you want to display the trash posts in the frontend dashboard, you can use the filter hook rwmb_frontend_dashboard_query_args
The frontend dashboard is a custom query to display posts belonging to a user so you can create your own query to display a custom dashboard on your own.
https://developer.wordpress.org/reference/classes/wp_query/April 12, 2023 at 4:56 PM #41455Way Leong
ParticipantHi, I applied the following php code into code snippets
<?php add_filter( 'rwmb_frontend_dashboard_query_args', 'my_frontend_dashboard_query_args' ); function my_frontend_dashboard_query_args( $args ) { $args['post_status'] = array( 'publish', 'trash' ); // Include trashed posts in the query return $args; } add_filter( 'wp_trash_post_status', 'my_trash_post_status', 10, 2 ); function my_trash_post_status( $trash_status, $post ) { $allowed_post_types = array( 'post','newsroom', 'property', 'leadership', 'company' ); // Set allowed post types if ( in_array( $post->post_type, $allowed_post_types ) ) { $trash_status = 'auto-draft'; // Set trashed posts to auto-draft status } return $trash_status; }
It does display the trashed post on the Frontend dashboard, but I am unable to edit the post even my user role is Admin. You may view the image here (https://prnt.sc/krDt4y39ovz8)
I applied this code to let the trashed post status to become auto-draft status
if ( in_array( $post->post_type, $allowed_post_types ) ) { $trash_status = 'auto-draft'; // Set trashed posts to auto-draft status } return $trash_status; }
April 12, 2023 at 6:36 PM #41459Peter
ModeratorHello,
>> It does display the trashed post on the Frontend dashboard, but I am unable to edit the post even my user role is Admin.
It is expected behavior. You are also not able to edit the trash post in the admin area, just restore it.
April 14, 2023 at 1:16 PM #41490Way Leong
ParticipantHi Peter,
Sorry for repeating this over again but I promise this would be the last.
add_filter( 'rwmb_frontend_dashboard_query_args', 'my_frontend_dashboard_query_args' ); function my_frontend_dashboard_query_args( $args ) { $args['post_status'] = array( 'publish', 'trash' ); // Include trashed posts in the query return $args; } add_filter( 'wp_trash_post_status', 'my_trash_post_status', 10, 2 ); function my_trash_post_status( $trash_status, $post ) { $allowed_post_types = array( 'post','newsroom', 'property', 'leadership', 'company' ); // Set allowed post types if ( in_array( $post->post_type, $allowed_post_types ) ) { $trash_status = 'auto-draft'; // Set trashed posts to auto-draft status } return $trash_status; } add_action( 'rwmb_frontend_after_delete_post', 'my_frontend_restore_post_status', 10, 2 ); function my_frontend_restore_post_status( $post_id, $post ) { if ( $post->post_status === 'trash' ) { $allowed_post_types = array( 'post','newsroom', 'property', 'leadership', 'company' ); // Set allowed post types if ( in_array( $post->post_type, $allowed_post_types ) ) { wp_update_post( array( 'ID' => $post_id, 'post_status' => 'draft' ) ); // Restore trashed posts to draft status } }
I tried to enable allowed edit for deleted post but the code doesn't seem working and it will still the same as this photo (https://prnt.sc/krDt4y39ovz8). Could you guide me on which PHP function is the correct one to allow deleted post to be edit?
-
AuthorPosts
- You must be logged in to reply to this topic.