Skip Navigation

[Resolved] Custom post type relationship doesn’t show the right connected posts

This thread is resolved. Here is a description of the problem and solution.

Problem:
Custom post type relationship doesn't show the right connected posts

Solution:
The problem with Views which show all of the posts of the related type rather than just the posts which are actually connected to the current post is because you are missing a Query Filter that specifies that only posts connected to the current post should be returned by the View query.

Go back to highlight the View block and in the Content Selection add a relationship Query Filter.

You can find the proposed solution in this case with the following reply:
https://toolset.com/forums/topic/custom-post-type-relationship-doesnt-show-the-right-connected-posts/#post-2299805

Relevant Documentation:
- https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
- https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_connect_posts

This support ticket is created 2 years, 2 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 9 replies, has 3 voices.

Last updated by Pierre 2 years, 2 months ago.

Assisted by: Minesh.

Author
Posts
#2291627

Tell us what you are trying to do?
I'm trying to show specific posts connected to a specific post type. But ALL posts are shown and not just the ones connected (in relation)?

Is there any documentation that you are following?
Tried a lot

Is there a similar example that we can see?
Please give me a private answer form and I will send you a video with description of the problem and give you access to the site.

What is the link to your site?

#2291799

Nigel
Supporter

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

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

I've set up a private reply for you...

#2298595

Nothing new on my support ticket?
6 days since I created it. My client needs a status report.

#2298657

Nigel
Supporter

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

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

Hi Pierre

I'm sorry, for some reason your first reply was lost, the ticket only now shows up again in the queue.

I watched your video.

I believe the problem with your Views which show all of the posts of the related type rather than just the posts which are actually connected to the current post is because you are missing a Query Filter that specifies that only posts connected to the current post should be returned by the View query.

Go back to highlight the View block and in the Content Selection add a relationship Query Filter.

#2298659

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

We are sorry but I'm not sure where this ticket could be lost.

I checked on your install and to display the related post, you will have to add the "Query Filter" to filter post by relationship.

To the content tempalte "Template for Dagar" where you added both your view.
=> hidden link

Under the view's Content Selection section you can add the "Query Filter" as you can see with the following screenshot:
=> hidden link

I've added the query filter for post-relationship for your both of the views:

 Filter by post relationship or repeatable fields group owner
Select posts in a Ankommande fartyg relationship that are related to the Post where this View is shown.

I can see the following post do not display any result:
- hidden link

I can see the following post does display the result:
- hidden link

More info:
- https://toolset.com/course-lesson/displaying-related-posts/

#2299737

Thank you for this.
Strange though but I tried those filters in different ways earlier without success. Glad it works now though 🙂

Unfortunately, a new problem occurred now.
Please see my screen video: hidden link

#2299739

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Both of your forms was missing the relationship field:
- hidden link
- hidden link

I've added the relationship field to both the form just before the submit button and now when you create the post it will be automatically linked to the current post.

#2299757

Ni Minesh,
Thank you for that prompt support.
When I try to add a post, I still don't see it getting added as connected?
You can try to add relationship posts here: hidden link
Please feel free to add whatever you like, the system is not online in a sharp environment.

#2299805

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I've added the following code to "Custom Code" section offered by Toolset:
=> hidden link

add_action('cred_save_data','func_connect_child_posts',15,2);
function func_connect_child_posts($post_id,$form_data) {
    if ($form_data['id']==54) {
         toolset_connect_posts('dag-ankommande',$_POST['@dag-ankommande_parent'], $post_id);
    }else if ($form_data['id']==81) {
      toolset_connect_posts('dag-utgaende',$_POST['@dag-utgaende_parent'], $post_id);
    }
}

I've also added the parent ID as hidden field as you do not want to display it as given under:
=> hidden link

	<input type="hidden" name="@dag-ankommande.parent" value="[wpv-post-id]"  class='form-control' />

=> hidden link

<input type="hidden" name="@dag-utgaende.parent" value="[wpv-post-id]" />

I can confirm now when I add new post its automatically connected:
- hidden link

#2299851

My issue is resolved now. Thank you very much Minesh!
/Pierre

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.