Skip Navigation

[Resolved] Relationship Form

This support ticket is created 2 years, 9 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 6 replies, has 3 voices.

Last updated by kellyR 2 years, 9 months ago.

Assisted by: Waqar.

Author
Posts
#2283183
toolset-220203-form-editor.jpg
toolset-220203-form-front-end.jpg

Tell us what you are trying to do?

I do not use "blocks" I have been using relationship forms to relate 2 custom post types (many to many). The "Person" post type is parent (left side in relationship) "Article" is child (right side).

I have created a relationship form for selecting the child. The form is brought up within a content template with a this shortcode [cred-relationship-form form='people-articles' parent_item="[wpv-search-term param='person_id']"] The purpose of this form is for creating an Intermediary post type linking to either post.

All goes well and the form shows the parent "Person" as a static selector and below that there is a selector to choose an "Article" to relate a "Person", see attached.

Now the problem is ALL published "Articles" are shown in "Article" selector, not just the parent "Person". This worked properly for years but now is a problem. I updated to Views version 3.6.2 yesterday and noticed the problem today but the issue may have gone unnoticed before.

About the form, the only options (which I never used before) are Options by any author" and "Options only by the current visitor". I did try all of the options but either got every Article or none.

I don't see any way to fix it, please help.

#2283721

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi there

I don't understand what the problem is.

The form is to connect an article to a specific person.

All articles are offered, and that is a problem?

Now the problem is ALL published "Articles" are shown in "Article" selector, not just the parent "Person".

I don't understand what you mean by "not just the parent Person".

Which articles should be offered to connect to a person?

#2283731

Only articles that belong to the parent person should be shown on the intermediary form.
When the form appears that person is already displayed on the form, in this case it is Janet Walker.
Only her Articles should be able to be selected, not all Articles by other People (a Person type post).
The idea is to link the Person to an Article, both are post types.
The shortcode asks for only Articles by the Author Janet Walker, not all Articles.

#2287355

Any ideas moving forward?

#2287401

Hi,

Thank you for sharing these details and we apologize for the delay.

I'm not sure how this ticket was left unattended, but I'll be following up on it now.

Can you please share temporary admin login details, along with the link to the page with this relationship form?

I'll be in a better position to suggest the next steps, accordingly.

Note: Your next reply will be private and it is recommended to make a complete backup copy, before sharing the access details.

regards,
Waqar

#2288679

Thank you for sharing these details.

During testing on my website with a similar setup, I was able to achieve this, using the following steps:

1. You'll need the custom shortcode that can the value of the "People" post ID from the URL parameter and then returns that post's author ID:


add_shortcode('get_author_from_URL', 'get_author_from_URL_func');
function get_author_from_URL_func($atts) {

	$a = shortcode_atts( array(
		'param' => '',
	), $atts );

	if( ( !empty($a['param']) ) && ( !empty($_GET[$a['param']]) ) ) {
		$URL_value = $_GET[$a['param']];
		$author_ID = do_shortcode("[wpv-post-author format='meta' meta='ID' item='".$URL_value."']");
		return $author_ID;
	}
}

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.

Also add "get_author_from_URL" in the "Third-party shortcode arguments" section, at WP Admin -> Toolset -> Settings -> Front-end Content.

2. Next, In your relationship form, turn on the "Expert mode".
( screenshot: hidden link )

3. In the form's code, you'll see this shortcode for the child (Articles) post field:


[cred-relationship-role role='child']

3. You can include this new custom shortcode as the value of the 'author' attribute in this field's shortcode like this:


[cred-relationship-role role='child' author='[get_author_from_URL param="person_id"]']

As a result, this child post field will only show those articles, where the post author is the user already selected in the parent (People) field ( in this particular case "Janet Walker").

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

#2288851

This works perfectly! Thank you so much, this was an enormous help to me.