Skip Navigation

[Resolved] Relationship Query Filter

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

Last updated by Minesh 3 years, 4 months ago.

Assisted by: Minesh.

Author
Posts
#1870789

I have a relationship query filter issue. I have a code provided by Toolset Supporter, Shane, to connect the child posts to the parent post automatically due to a 3rd party plugin that generates the child post based on the information from our API. Which works ONLY if I remove the query filter- “Filter by post relationship or repeatable fields group owner” However, removal of that relation query filter doesn’t display only the related child posts of the parent post. It displays all children posts of that type. Is there additional code that you can add on to fix the issue?

https://toolset.com/forums/topic/using-php-to-attach-hazard-productcpt-posts-to-the-major-hazardcpt-parent/

#1871491

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Can you please share details where you are using the code that connects the posts automatically using the code shared by Shane as well as share what view you are using where you added the post relationship filter and where you are displaying that view.

If I will not able to track this I will pass this ticket to Shane.

*** 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.

#1873121

Minesh
Supporter

Languages: English (English )

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

I checked you are connecting the post from the following view:
=> hidden link

Where you added the function:

[connect_posts parent_id='[wpv-post-id item="$current_page"]' child_id='[wpv-post-id]'] 

I would like to know how you are adding child posts as you will require to connect each child post with the desired parent and I see not child is connected to parent post.

How you are adding/importing child post and how you are connecting them?

If you are using the following line of code:

[connect_posts parent_id='[wpv-post-id item="$current_page"]' child_id='[wpv-post-id]'] 

the above line of code is added to outside the view's loop and it will not work as it will not have [wpv-post-id] value as you added it outside the view's loop as you can see with your view:
=> hidden link

#1873601

The addition of child posts is done by a 3rd party plugin that generates new child posts every time the page is visited. It will populate the information in the custom fields. I would like to connect them based on a shared custom field (slug: hazard_id)

If you remove the relationship query filter (Select posts in Any relationship that are related to the Post where this View is shown.) from the view. It will display all the child posts.

Where do you suggest I place the following line of code? I’ve even tried placing it within the Loop item in Test Hazard Products view and that hasn't worked either.

#1875295

Minesh
Supporter

Languages: English (English )

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

I would like to know what is the parent post and from where it will generate the child post automatically?

I will the whole work flow what page I will require to visit using which it will generate the child post automatically and what will be the parent post in that case?

#1876615

The parent posts are Test Major Hazards. There are two posts available that can generate the child posts. If you view one of the parent posts. For example: "TC - Bongoyo", it shows that child posts are generated. But because the Test Hazard Products view has the relationship query filter, it doesn't display. You can remove that query filter and refresh either of the parent posts. Then you'll be able to see the issue and child posts.

#1876677

Minesh
Supporter

Languages: English (English )

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

There is a strange thing happening:

If you visit the following parent post:
=> hidden link

You will see 9 posts within the post-relationship box "Test Major Hazards Test Hazard Products", but if you click any of those available 9 post, when you click on it, it says "You attempted to edit an item that doesn’t exist. Perhaps it was deleted?".

The thing is that, if you have post relationship created - there must be posts connected within the post relationship, in your case, 9 posts are connected but when we try to access those posts the are not longer accessible, so that is garbage posts may be.

So, I suggest you should remove all garbage related posts (all those 9 posts) from your following parent post:
=> hidden link

If you allow, can I remove those garbase posts and connect few actual posts and test?

#1877827

I don't believe the custom code: "connect hp posts" is working.
You may remove the posts and connect actual posts and test.

#1877837

Minesh
Supporter

Languages: English (English )

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

As you can see with the following parent post, i've connected two child post within the post relationship box:
=> hidden link

Then i've created the following test view:
=> hidden link

And added that view with the label "Test View" on the post body of your parent post:
=> hidden link

When I check the parent post on the frontend:
- hidden link

I can see it display those two connected posts.

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