WordPress

Contents

Cleanup Database

To delete orphaned post meta, use this query:

DELETE FROM wp_postmeta WHERE post_id NOT IN (SELECT ID FROM wp_posts);

To delete post meta from revisions, use this query:

DELETE FROM wp_postmeta WHERE post_id IN (SELECT ID FROM wp_posts WHERE post_type = 'revision');

Finally, delete the revisions from your database:

DELETE FROM wp_posts WHERE post_type = 'revision';

Custom Post Types with SVG menu icon

To use SVG icons for your Custom Post Types in WordPress, encode the SVG in base64. Make sure that your SVG includes currentColor to match the WordPress menu.

register_post_type(
    'product',
    [
        'menu_icon' =>
            'data:image/svg+xml;base64,' .
            base64_encode(
                '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M11.644 1.59a.75.75 0 0 1 .712 0l9.75 5.25a.75.75 0 0 1 0 1.32l-9.75 5.25a.75.75 0 0 1-.712 0l-9.75-5.25a.75.75 0 0 1 0-1.32l9.75-5.25z"/><path d="m3.265 10.602 7.668 4.129a2.25 2.25 0 0 0 2.134 0l7.668-4.13 1.37.739a.75.75 0 0 1 0 1.32l-9.75 5.25a.75.75 0 0 1-.71 0l-9.75-5.25a.75.75 0 0 1 0-1.32l1.37-.738z"/><path d="m10.933 19.231-7.668-4.13-1.37.739a.75.75 0 0 0 0 1.32l9.75 5.25c.221.12.489.12.71 0l9.75-5.25a.75.75 0 0 0 0-1.32l-1.37-.738-7.668 4.13a2.25 2.25 0 0 1-2.134-.001z"/></svg>'
            ),
    ],
);

Plugins

Update URLs

To update URLs in your database, use the following queries:

UPDATE wp_options SET option_value = REPLACE(option_value, 'old.com', 'www.new.com');
UPDATE wp_postmeta SET meta_value = REPLACE(meta_value, 'old.com', 'www.new.com');
UPDATE wp_posts SET guid = REPLACE(guid, 'old.com', 'www.new.com');
UPDATE wp_posts SET post_content = REPLACE(post_content, 'old.com', 'www.new.com');