Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
1  
Add the name of that custom field to your question. –  toscho Oct 31 '12 at 0:58
1  
To find the custom field name, I've searched for one specific word of a AOISEOP description in PHPMyAdmin. –  brasofilo Oct 31 '12 at 1:20

2 Answers 2

up vote 1 down vote accepted

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.

share|improve this answer
    
Wow sounds neat! I will test it out and get back to you. Thanks for taking this on. :) –  Drewdavid Nov 1 '12 at 20:02
    
Hi and thanks for this, it's working perfectly. Is there a way to modify this so that it continues to perform this action, post after post? I have had to deactivate and reactivate it after publishing each post to keep up. Wondering if there's a way to automate it or if you'd recommend a different solution. Thanks :) –  Drewdavid Dec 6 '12 at 21:03
    
Hi, look at this results and search for those hooks usage. Or open a new Question :) –  brasofilo Dec 6 '12 at 21:14
    
@Drewdavid please mark this answer as correct if it's working perfectly. –  pendjer Dec 10 '13 at 14:06

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.