-
-
Notifications
You must be signed in to change notification settings - Fork 101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add relationships between (a) posts and attachments and (b) posts and featured images #1446
Add relationships between (a) posts and attachments and (b) posts and featured images #1446
Conversation
…st and any attachment it uses
I'm for leaving without the date. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great feature!
Tests are failing only because #1429 needs to be merged first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving again after past core meeting.
I've pushed a commit to bump |
There is currently no sensible way to find which media files are being used on which posts or pages (and which are not being used at all). This problem was even the subject of an article in WP Tavern: https://wptavern.com/the-problem-with-image-attachments-in-wordpress
After that article, a plugin was created to address the problem: see https://wordpress.org/plugins/find-posts-using-attachment/
That plugin has had mixed reviews, and it works by relying on querying post meta to find posts. That's a notoriously slow and problematic query, and it won't scale.
This PR presents its results in a manner inspired by that plugin, as seen below:
![image](https://private-user-images.githubusercontent.com/4127662/331046351-5566eca8-cf77-44c7-aed3-fb9f0e74e4cc.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjA1NjYxOTUsIm5iZiI6MTcyMDU2NTg5NSwicGF0aCI6Ii80MTI3NjYyLzMzMTA0NjM1MS01NTY2ZWNhOC1jZjc3LTQ0YzctYWVkMy1mYjlmMGU3NGU0Y2MucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDcwOSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA3MDlUMjI1ODE1WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9NThmZDkyYzM4MDQ4MWIzOGFjYWE2NDM5OGM4MzYxMGUxZjQ5OTQzMWI3MjlhM2E3ZGNmM2YxZjBiMjhlNjllZiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.HliyaMlyKHC-931an40gcFBOBO-tBF4P3feZ9x5gNJ4)
But this PR generates those results in a very different way from that plugin. Rather than rely on querying metadata, it uses the object relationships table that is the subject of PR #1429. For this reason, that PR must be merged before this one.
But this PR has wider implications because it provides an easy way not only to find either a featured image or an attachment (a media file used in the post's content) from a post but also to find a post from either a featured image or an attachment. Note: "post" here includes pages and all custom post types.
Once PR #1429 and this PR are merged, relationships between new posts and their associated featured image or attachments will automatically be kept up to date. Older posts and their associates will be brought up to date when re-saved.
Closes #1435.