-
AuthorPosts
-
July 10, 2020 at 11:03 am #1229375
I am trying to clean my bloated database.
In the wp_postmeta table I see thousands of _wp_old_slug rows. I am not concerned about these old links not being redirected. What are the pros and cons of removing them?
See: https://www.farinspace.com/removing-wordpress-old-post-slug/
In the wp_postmeta table I see hundreds of _wp_old_date rows. I am not concerned about knowing when a post was originally written. I am only concerned about the most recent ‘published on’ date and want to continue displaying the most recent ‘published on’ date on posts. What are the pros and cons of removing them?
This website shows old tables and options rows developers often leave behind after uninstalling plugins, since WordPress does not require developers to give users the option of removing all data when uninstalling.
Any other suggestions to clean the database and to keep it clean? Thank you.
July 14, 2020 at 6:49 am #1230173Hey classywebsites,
Thank you for the inquiry.
We are not really sure how will this affect the installation because we haven’t really tried removing those entries before. But it looks like it is used by WordPress to check if the post date has changed. Removing it will probably not make any difference because WordPress will still generate it back once the posts are updated.
// Redirect Old Dates add_action( 'post_updated', 'wp_check_for_changed_dates', 12, 3 ); add_action( 'attachment_updated', 'wp_check_for_changed_dates', 12, 3 ); function wp_check_for_changed_dates( $post_id, $post, $post_before ) { $previous_date = date( 'Y-m-d', strtotime( $post_before->post_date ) ); $new_date = date( 'Y-m-d', strtotime( $post->post_date ) ); // Don't bother if it hasn't changed. if ( $new_date == $previous_date ) { return; } // We're only concerned with published, non-hierarchical objects. if ( ! ( 'publish' === $post->post_status || ( 'attachment' === get_post_type( $post ) && 'inherit' === $post->post_status ) ) || is_post_type_hierarchical( $post->post_type ) ) { return; } $old_dates = (array) get_post_meta( $post_id, '_wp_old_date' ); // If we haven't added this old date before, add it now. if ( ! empty( $previous_date ) && ! in_array( $previous_date, $old_dates ) ) { add_post_meta( $post_id, '_wp_old_date', $previous_date ); } // If the new slug was used previously, delete it from the list. if ( in_array( $new_date, $old_dates ) ) { delete_post_meta( $post_id, '_wp_old_date', $new_date ); } }
If you really want to test it, make sure to create a backup or a restore point first.
Best regards,
IsmaelJuly 18, 2020 at 2:30 am #1231400Hi Ismael,
Thank you for your detailed response.
I was simply going to search the wp_postmeta table and remove any instances of wp_old_slug and any instances of WP_old_date.
Is your recommendation to add your code to the function.php file?
I read the remarks in your code. Can you please explain what it is really doing?
Thank you.July 20, 2020 at 8:15 am #1231643Hi,
Thank you for the update.
The code above is already included in the WP core, so you don’t need to add it. It checks if the post date has changed and will regenerate the _wp_old_date entry whenever necessary.
Best regards,
IsmaelJuly 20, 2020 at 5:03 pm #1231797Hi Ismael,
Thank you for clarifying the code is the core WordPress code.
Where can I go to learn more about slug function and storage in the database?
Thank you.- This reply was modified 4 years, 5 months ago by classywebsites.
July 21, 2020 at 6:52 am #1231951Hi,
Almost all functions in the core are available in the documentation.
You can check it out here.
// https://developer.wordpress.org/reference/functions/wp_check_for_changed_dates/
The actual code can be viewed in the Trac.
// https://core.trac.wordpress.org/browser/tags/5.4/src/wp-includes/post.php#L6287
Thank you for your patience.
Best regards,
Ismael -
AuthorPosts
- You must be logged in to reply to this topic.