On this site, users can add a post via a front-end form, which gets the status "private". But the user should be able to see and edit (only) his own private post. When I give the user role "read_private_posts" permission in Access, he can also see other peoples private posts. Thats not what we want.
Hello. Thank you for contacting the Toolset support.
Can you please share problem URL where you added the form as well as admin access details.
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I have set the next reply to private which means only you and I have access to it.
I see you are using post type archive to display the posts on the fllowing archive:
=> versteckter Link
Here is the archive in the backend.
- versteckter Link
I'm not sure why the "Query Filter" section is not available under the "Loop Selection" tab on the right sidebar.
We can filter the posts based on the post author. So, when you add the post from the frontend, user must be logged in - correct? if yes:
- You must set that post author as the current loggedin user. So we can identify that this post is created by this current loggedin user.
Then later on, with the post type archive you crated for the "schip" we can filter the posts based on the post authror equal to the current loggedin user. Is that sounds good?
So, my question is do you set current loggedin user as the author of the post when user create posts from the frontend?
A logged-in user should be able to see all ships / posts. But some of those are published as a private post, and they should only see their own private post. So they should see all public published posts, but not private posts except for their own.
So basically, you want to exaclude the private posts created by other users and display all public posts from current as well as other users and private post of the current user.
This code showed all private posts, not just the private posts of the author. But I put this in AI and let it fix it. It gave me the following working code:
function filter_schip_posts_for_schipper($query) {
if (!is_admin() && $query->get('post_type') == 'schip' && $query->is_main_query()) {
if (!is_user_logged_in()) {
// Niet ingelogd → alleen public
$query->set('post_status', 'publish');
return;
}
$current_user_id = get_current_user_id();
// Hier maken we een OR-structuur: publish van iedereen OR private van jezelf
$query->set('post_status', array('publish', 'private'));
$query->set('author', ''); // eerst alles toestaan
// WordPress filter om alleen eigen private posts te tonen
add_filter('posts_where', function($where, $q) use ($current_user_id) {
global $wpdb;
// alleen toepassen op onze 'schip' query
if ($q->get('post_type') != 'schip') return $where;
$where .= " AND ({$wpdb->posts}.post_status = 'publish' OR ({$wpdb->posts}.post_status = 'private' AND {$wpdb->posts}.post_author = {$current_user_id}))";