Skip Navigation

[Resolved] Split: Child Post user show

This support ticket is created 2 years, 3 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 7 replies, has 3 voices.

Last updated by Waqar 2 years, 3 months ago.

Assisted by: Waqar.

Author
Posts
#2448343

sorry, the question is still actual for child posts way.

Post type 1 link with Post type 2 child post.
User2 is author of Post type 2.
User1 is author of Post type 1.

How to display Post type 1 for the User2?

Thank you in advance!
Anton

#2448345

Christopher Amirian
Supporter

Languages: English (English )

Hi there,

Would you please kindly reply back by making sure you set the next reply as private and add the login information and give details of the setup with proper links?

Also please give me more information if you have custom fields that might have anything to do with the users or any details that help me understand ithe ssue.

Please consider that I am new to your setup, and as you do know your setup I do not. So try to explain from scratch which post types you have, what you have done with the views and what you want to achieve.

Thank you.

#2448755

Hi Anton,

Thank you for sharing these details and I'll be following up on this ticket.

After reviewing your website's setup, here is what I understand:

- all users on your website will have exactly one "ВОЛШЕБНИК" (wizards) post where they'll be the post author.

- and the "ВОЛШЕБНИК" post type is linked through a one-to-many post-relationship to the "Артели" post type ( where 1 'Артели' post can have many 'ВОЛШЕБНИК' posts ).

- the purpose of the "Артели" post type is to group the similar "ВОЛШЕБНИК" posts.

- and you'd like to show the list of each group or the "Артели" post so that only the users related to that group can see that list.

If my understanding is correct, I do have some questions to better understand the requirement further.

When you already have the list of related 'ВОЛШЕБНИК' posts on the single "Артели" post page ( e.g. hidden link ), do you really need a separate page for showing the related 'ВОЛШЕБНИК' posts ( e.g. hidden link )?

Would it work if the user access restrictions could be added to each single "Артели" post page ( e.g. hidden link )?

Please let me know the answer to these questions so that I can suggest the next steps of adding user restrictions to the list.

regards,
Waqar

#2449889

Waqar, your understanding correct.

Your Question:
When you already have the list of related 'ВОЛШЕБНИК' posts on the single "Артели" post page ( e.g. hidden link ), do you really need a separate page for showing the related 'ВОЛШЕБНИК' posts ( e.g. hidden link )?

Answer:
Yes. This is the main my question. Users come on this page ( e.g. hidden link ) and should see only posts where they are in.

Please notice that there are set up of grandparent, parent and grandchild posts.

Your Question:
Would it work if the user access restrictions could be added to each single "Артели" post page ( e.g. hidden link )?

Answer:
Independently from the above question, could you please advise details how to do this.

Thank you in advance!
Sincerely
Anton

#2451109

Thank you for confirming this.

This restriction will require some custom code and I'm currently running some tests on my website, to find the most efficient way to achieve this.

I'll share my findings, as soon as this testing completes. Thank you for your patience.

#2452043

Thank you for waiting.

I'm having difficulty accessing certain sections of the website's admin area, probably due to server restrictions or a security firewall.

Do I have your permission to download a clone/snapshot of your website, to test the proposed solution on a different server?

Once it works, I'll be able to share the steps with you so that you can implement this on the actual website too.

#2453181

unfortunately no. Maybe this difficulty because several users worked on incidents. Could you please try once more.

#2453807

Thank you for waiting.

Here are the steps, that I'll recommend for restricting access to the single "Артели" post pages ( e.g. hidden link ), so that only the users who have a related "ВОЛШЕБНИК" post attached to it, can view it.

1. The "Артель" content template is set to show the regular content on the single "Артели" post pages. But, you'll create a new content template named something like "Not allowed" so that it is shown to the users who are not allowed access.

You can add any message in this template like "You're not allowed to view this page" etc and you don't have to assign this page to any post type.

2. Next, you'll need a custom function attached to the "wpv_filter_force_template" filter, which will decide whether to show the regular "Артель" content template or the "Not allowed" content template, based on the current user:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_force_template

Example:


add_filter( 'wpv_filter_force_template', 'prefix_restrict_Артель_template', 101, 3 );
function prefix_restrict_Артель_template( $template_selected, $id, $kind ) {
	if($kind == 'single-artel') {
		$not_allowed_template_id = '12345';
		$current_user_id = get_current_user_id();
		if ( $current_user_id == 0 ) {
			$template_selected = $not_allowed_template_id;
		}
		else
		{
			$args = array(
				'post_type'        => 'volshebnik',
				'posts_per_page'   => -1,
				'post_status'      => 'publish',
				'author'		   => $current_user_id,
				'fields'		   => 'ids'
			);

			$posts_array = get_posts( $args );
			if (!empty($posts_array)) {
				$related = array();
				foreach ($posts_array as $posts_array) {
					$related_parent = toolset_get_related_post( $posts_array, 'volshebnikiartelya', 'parent' );
					if($related_parent == $id) {
						$related[] = $related_parent;
					}
				}
				if(empty($related)) {
					$template_selected = $not_allowed_template_id;
				}
			}
			else
			{
				$template_selected = $not_allowed_template_id;
			}
		}

	}
	return $template_selected;
}

Note: Please replace '12345' with the actual ID of the newly created "Not allowed" content template.

The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through the active theme's "functions.php" file.

After this code has been added, non-logged in guests and the user's who are not linked to the current "Артели" post, will see a "not allowed" message, while the users who are linked to the current "Артели" post, will see the regular content.

I hope this helps and please let me know if you need any further assistance around this.