admin管理员组

文章数量:1135117


Just switched WP themes and I have about 1300 media files attached to what Wordpress is calling a 'Private Post'.

These Private Posts are actually photo portfolios from the previous theme. 200 portfolios, with 5-7 media files attached to each.

I need to detach this media before it can be used in the new theme. Right now its a manual, tedious process :(

I am hoping there is something I can change in the DB to detach these media files in one go. Any help appreciated. Thanks in advance.


Just switched WP themes and I have about 1300 media files attached to what Wordpress is calling a 'Private Post'.

These Private Posts are actually photo portfolios from the previous theme. 200 portfolios, with 5-7 media files attached to each.

I need to detach this media before it can be used in the new theme. Right now its a manual, tedious process :(

I am hoping there is something I can change in the DB to detach these media files in one go. Any help appreciated. Thanks in advance.

Share Improve this question asked Aug 15, 2023 at 19:06 Elemental MediaElemental Media 1 11
  • what makes the post "attached" to another post is the post_parent field, the same mechanism used for child/parent pages. The Media in the media library is actually a post of type attachment. Note that you shouldn't need to detach them to be able to use another theme, and you can use the same attachment in multiple places even if it's already set to be "attached" to a single post – Tom J Nowell Commented Aug 15, 2023 at 19:33
  • Thank you for your quick reply Tom, I appreciate it. Here is a screenshot of my current situation: share.getcloudapp.com/rRuzxG0X These are images attached to a portfolio meta type contained in the previous theme. I dont see any way to attach them to another post without detaching from existing 'ghost/private post' first. – Elemental Media Commented Aug 15, 2023 at 19:40
  • you don't need to attach them to be able to use them, what's the problem in the new theme you're trying to solve that requires you to re-attach them? Note that any custom post types the previous theme registered are still present in the database even if the new theme doesn't register them, they aren't lost forever – Tom J Nowell Commented Aug 15, 2023 at 19:48
  • I am using a gallery plugin that uses a shortcode for each portfolio item, that attaches the media as a gallery to that specific portfolio (where the media is attached). – Elemental Media Commented Aug 15, 2023 at 19:50
  • would I be right to guess that you're doing this so you can create new pages with that shortcode and attach the images to them so you can get your portfolios on the new theme? – Tom J Nowell Commented Aug 15, 2023 at 19:51
 |  Show 6 more comments

1 Answer 1

Reset to default 1

You should register the post type from the old theme, all the posts are still there in the database WordPress just doesn't know to look for them.

Use the register_post_type with the same slug/post type name, and your old portfolio posts will reappear, no need to detach and re-attach to new pages

本文标签: custom post typesDetach Wordpress Media Files In Bulk