Skip to content
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

Merged
merged 14 commits into from
Jul 1, 2024

Conversation

KTS915
Copy link
Member

@KTS915 KTS915 commented May 16, 2024

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

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.

@KTS915 KTS915 changed the title Add relationshps between (a) posts and attachments and (b) posts and featured images Add relationships between (a) posts and attachments and (b) posts and featured images May 16, 2024
@KTS915
Copy link
Member Author

KTS915 commented May 17, 2024

Latest commit splits featured images off into their own column, which I think makes things both clearer and cleaner than before.
image

The one thing I'm not sure of now is whether the date should be appended to the post name. I think it would look nicer without the date, but maybe that's useful information for some users. What do others think?

@xxsimoxx
Copy link
Member

I'm for leaving without the date.

Copy link
Member

@xxsimoxx xxsimoxx left a 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.

Copy link
Member

@xxsimoxx xxsimoxx left a 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.

@xxsimoxx
Copy link
Member

xxsimoxx commented Jul 1, 2024

I've pushed a commit to bump $cp_db_version to 1446 after testing on another host.
The tables were not in place, so if the new functions are called from this PR it can lead to errors.

@mattyrob mattyrob merged commit d9c6035 into ClassicPress:develop Jul 1, 2024
20 checks passed
@KTS915 KTS915 deleted the post-attachment-relationship branch July 2, 2024 18:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

💡 Add Postmeta to Each Attachment to Store Array of IDs of Posts Where Attachment is Used
3 participants