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