Skip Navigation

[Resolved] Split: View Empty Relationships – check for other post-relationship

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 10 replies, has 3 voices.

Last updated by Minesh 7 months, 3 weeks ago.

Assisted by: Minesh.

Author
Posts
#2703412

I tried to use the same coding with alterations for different relationships but had no success.

The ladies-results post type has 4 different one to many relationships. I'm trying to make 4 different views that will find the posts that are missing any of these relationships. It works for the nation-sc to ladies-results relationship but not for the others. The other 3 are ladies, ladies-event, and club-sc.
When I change the slugs and view id, it either never loads the page, or crashes. Even if I lower the amount of posts to display to 2.

You can use the same view id just swap out different custom code for each. As I noticed that a fatal error occurred if I had 2 codes active.
Thanks

#2703423

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Well - you will have to change the filter hook function name.

For example:

add_filter('wpv_filter_query', 'func_show_only_child_where_parent_is_set_1', 10, 3);
function func_show_only_child_where_parent_is_set_1($query, $view_settings, $view_id) {

  //// all code goes here
}

add_filter('wpv_filter_query', 'func_show_only_child_where_parent_is_set_2', 10, 3);
function func_show_only_child_where_parent_is_set_2($query, $view_settings, $view_id) {

  //// all code goes here
}

add_filter('wpv_filter_query', 'func_show_only_child_where_parent_is_set_3', 10, 3);
function func_show_only_child_where_parent_is_set_3($query, $view_settings, $view_id) {

  //// all code goes here
}

You can give any function name and check if that help you to resolve your issue.

#2703430

That only solves having two or more filter hooks active. That does not solve why the view does not load and crashes.

#2703433

Minesh
Supporter

Languages: English (English )

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

Can you please tell me where exactly you added the another hook and for what view and on what page you added the view that crashes?

Please share problem URL where view is crashes and for what post relationship you want to display what.

I have set the next reply to private which means only you and I have access to it.

#2703439

Same as the last one. I deactivated the old one and put the new one on the same view and page.

#2703470

Minesh
Supporter

Languages: English (English )

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

I can see you have post-relationship: ladies_ladies-results

When I checked you have 8,741 items for parent ladies and 28,965 items for ladies-results. That is too much and that is why page is crashed as its too much even without Toolset these many items to query its a resource extensive task.

There is no way to query all those posts at a time either parent or child as with parent ladies (8,741 items) and child ladies-results (28,965 items).

You will have to think in different way to display this.

Maybe you can add a field "Does Parent Exists?" that hold the status, if the post has parent assigned then set this field otherwise not and then we can query to find posts where "Does Parent Exists?" field is not set or even you can think how you want to manage this if you have any other better idea.

#2703494

There is already a field "skaters-name" that is the same as the relationship "ladies_ladies-results" in the "ladies-results" posts.
But how can you do a view to list only the ones that do no match, at the view query filter and not at the loop?
Can you do a filter hook for that ?

I need to find all the posts that have lost relationships due to a major problem, caused by "importer custom fields pro" and "toolset post reference fields". Which is another issue I still have to resolve.

#2703532

Nigel
Supporter

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

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

Might I offer a suggestion?

I understand you are trying to do this not because you actually want to display the orphan child posts that don't have a parent post, but because you want to locate them so that you can fix problems with your data.

Given the size of the tables and the problems you are having doing this with Views, I suggest you try querying the database directly, with specific SQL queries designed to locate those orphans.

Do you have access to phpMyAdmin to be able to inspect your database directly and run SQL queries? If not you could add an Adminer plugin that offers the same from within the WordPress back end: https://wordpress.org/plugins/pexlechris-adminer/

You will need the IDs of the relationships you want to test for, so the first thing is to check the wp_toolset_relationships table and note down the IDs. (I'm assuming the default 'wp_' table prefix throughout this reply, you will need to adjust if you use a custom prefix.)

You can then use a custom SQL query to check for each relationship you are concerned with, which you will edit to update the relationship ID, as well as the post type of the child posts (on my test site I was working with the Tasks post type, so the slug I use below is 'task').

Here's the query you can try:

SELECT 
    posts.ID, posts.post_title
FROM 
    wp_posts posts 
LEFT JOIN
    wp_toolset_connected_elements elements 
ON
    elements.element_id = posts.ID
LEFT JOIN
    wp_toolset_associations associations
ON
    associations.child_id = elements.id
    AND associations.relationship_id = 1
WHERE
    posts.post_type = 'task' 
    AND posts.post_status = 'publish'
    AND (elements.element_id IS NULL OR associations.child_id IS NULL)

Try that. If you get stuck Minesh should be able to help.

#2703657

Minesh
Supporter

Languages: English (English )

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

Can you please try to follow the suggested workaround by Nigel with the following reply:
- https://toolset.com/forums/topic/split-view-empty-relationships-check-for-other-post-relationship/#post-2703532

#2704347

As per your reply https://toolset.com/forums/topic/split-view-empty-relationships-check-for-other-post-relationship/#post-2703470

I do not need to query all the related posts (ladies of 8,741 items) just the main post type ladies-results.
Can you not just query the ladies-results post type and list the posts that have no ladies_ladies-results relationship ?
OR. just list the ones where the related post title does not match the text field skaters-name ?

I can already do both ways in the view loop with page breaks. I would prefer it to be done before the view loop.

As per the way Nigel suggested -- I'm still looking into that.

#2704610

Minesh
Supporter

Languages: English (English )

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

Well - anyways.

You have 8,741 items for parent ladies and 28,965 items for ladies-results.

Even you query only ladies-results that has 28,965 items (posts) and that is too much.

As I shared before even without using Toolset to deal with that number of posts and update it is challenging task.

I suggest you get in touch with any database expert and check with them how you can deal with the issue you shared here. I'm afraid that there is no other solution we can offer.