• Resolved Ari123

    (@ucdguy)


    Hi,

    Thank you for a great plugin!

    I would like to revert all of my meta titles and descriptions for a particular post type (and not the others) back to their original generated titles and descriptions.

    Are there hooks (or other methods) of achieving this?

    Thank you for your help! ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Sybre Waaijer

    (@cybr)

    Hello!

    That’s an odd request ??.

    Nevertheless, this snippet below should help you. MAKE A BACKUP of your database first.

    Then, add the snippet to your theme’s functions.php file and login in wp-admin. It should delete all the custom TSF title and description data from the post type example_post_type. Change example_post_type with the post type name you wish to purge data from.

    When after that, you can immediately delete the snippet; otherwise, it’ll keep trying to delete the data forever.

    function my_delete_metadata_keys_from_posts() {
    
        if ( ! is_super_admin() ) return;
    
        global $wpdb;
    
        $post_type = 'example_post_type';
        $meta_keys = [ '_genesis_title', '_tsf_title_no_blogname', '_genesis_description' ];
    
        foreach ( $meta_keys as $meta_key ) {
            $wpdb->query( $wpdb->prepare( "
                DELETE FROM {$wpdb->postmeta}
                WHERE meta_key = %s
                AND post_id IN (
                    SELECT ID
                    FROM {$wpdb->posts}
                    WHERE post_type = %s
                )
            ", $meta_key, $post_type ) );
        }
    }
    
    add_action( 'admin_init', 'my_delete_metadata_keys_from_posts' );
    • This reply was modified 1 year, 7 months ago by Sybre Waaijer. Reason: clarity
    Thread Starter Ari123

    (@ucdguy)

    Hi,

    Thank you for your quick reply, greatly appreciated!

    “That’s an odd request.”

    The reason why I wish to do this is because I’m using both “the_seo_framework_title_from_generation” and “the_seo_framework_generated_description” to change the generated meta titles and descriptions for a particular post type to something else.

    I want these new filters to apply to all of my posts of a particular type, including old and new posts. However, the filters that I create only seem to work on 1) new posts or on 2) old posts in which generated titles/descriptions are still used.

    If I also want these filters that I’ve created to also override 3) old posts in which custom titles/descriptions are used, I believe that I have to first “reset” those custom titles/descriptions to generated titles/descriptions.

    Is that correct? And is the code above the best way of achieving that?

    Thank you for your help! ??

    Plugin Author Sybre Waaijer

    (@cybr)

    Hi again!

    My reply wasn’t that quick, but I appreciate the appreciation ??

    There’s a certain order to how a title is created:

    1. Get the custom title, and apply a filter “custom” to that.
    2. If a title is found, add optional prefixes, conditional pagination, and optional branding.
    3. Otherwise, generate a title, apply a filter “generated” to that, and add optional prefixes, conditional pagination, and optional branding.

    If you generate a title, then the user should be able to overwrite it via TSF’s interface. It would confuse the user if the interface no longer works as intended. Hence, I rarely suggest using filter “custom.”

    If you’re the only user on the site, or if you provide an alternative interface for the custom title or remove the old interface altogether, you can use the “custom” filter: the_seo_framework_title_from_custom_field. Note that this filter renders useless the title input fields and their character and pixel counters. The SEO Bar should still work accordingly and accept the filtered value, though its explanatory on-hover tooltips may be less accurate.

    The description creation order is a little simpler:

    1. Get the custom description, and apply the filter “custom” to that.
    2. If no description is found, generate a description, and apply various filters to that.

    The same issue concerning custom titles also affects descriptions. Keeping that in mind, use it with caution: the_seo_framework_custom_field_description.

    Ultimately, you should decide whether to remove the custom inputs or overwrite them.

    • This reply was modified 1 year, 7 months ago by Sybre Waaijer. Reason: clarity
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Revert to Generated Titles & Descriptions?’ is closed to new replies.