Copy SEO Meta Desc “Custom Field” to Excerpt field?

I’d really like to take all of my old posts, and automatically use the meta descriptions we have written – currently done for each post using All In One SEO Pack – and copy them to also be our post excerpts.

The custom field used by AIO SEO description is _aioseop_description.

Would anyone have any idea how to accomplish this?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Please, backup your database before running this.

The code is pretty straight forward and tested in a local WordPress.
The advice is just for precaution sake, as I suppose you’re dealing with a live site.

Copy the code into a PHP file, upload it to the plugins folder and activate.

  1. On activation, it will iterate through all the posts post type and check if it has an excerpt.
  2. If not, check if there is an All In One description.
  3. If there is, fill the excerpt with this info.
<?php
/*
    Plugin Name: AIOSEOP to Excerpt
    Plugin URI: http://wordpress.stackexchange.com/q/70990/12615
*/
register_activation_hook( __FILE__, 'wpse_70990_activation_run' );

function wpse_70990_activation_run()
{   
    $args = array( 
        'post_type'   => 'post'
    ,   'numberposts' => -1
    ,   'post_status' => published 
    );
    $posts = get_posts( $args );
    foreach ( $posts as $post )
    {
        if( '' == $post->post_excerpt )
        {
            $aioseop = get_post_meta( $post->ID, '_aioseop_description' ,true);
            if( '' != $aioseop )
            {
                $po = array();
                $po = get_post( $post->ID, 'ARRAY_A' );
                $po['post_excerpt'] = $aioseop;
                wp_update_post($po);
            }
        }
    }   
}

Documentation: register_activation_hook, get_posts, get_post, wp_update_post.

Method 2

I couldn’t find the answer for this, so I developed a plugin that will add the description from the All in One SEO Pack and save it as a description for all the posts in your WordPress blog.

You can download it from here. Be sure to backup your database first.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x