Get Yoast SEO Data

By Dean Andrews | Posted on October 30, 2012

I love the On-page Optimisation in MOZ. This feature allows you to enter your focus keyword against a page for the url you wish to score.
Personally I add my focus keywords with a label just to keep it tidy when reporting back. However you can not extract the url from the database as it is created via the get_permalink() or get_page_link() functions.
I created GetYoastData which outputs to the browser the required data that can be saved into an csv (Excel) file.

Grab the code below and save it to a file called GetYoastData.php
Upload via FTP to the root directory (where the config.php file is)
Visit page www.YOUR-DOMAIN.COM/GetYoastData.php
Select save page as GetYoastData.txt (Yes save as .txt)
Open excel and open your GetYoastData.txt file
Delete GetYoastData.php via FTP as I wouldn’t leave it hanging around for your competitors to find

<?php

/*
Version: 1.0
Date: 29/10/2012
Source: http://www.deanandrews.co.uk/get-yoast-seo-data/

Upload via FTP to the root directory (where the config.php file is)
Visit page www.YOUR-DOMAIN.COM/GetYoastData.php
Select save page as GetYoastData.txt (Yes save as .txt)
Open excel and open your GetYoastData.txt file
Delete GetYoastData.php via FTP as I wouldn't leave it hanging around for your competitors to find

Note:
This code is provided "as is" and any expressed or implied warranties, including, but not limited to, 
the implied warranties of merchantability and fitness for a particular purpose are disclaimed. 
In no event shall the regents or contributors be liable for any direct, indirect, incidental, special, exemplary, 
or consequential damages (including, but not limited to, procurement of substitute goods or services; loss of use, 
data, or profits; or business interruption) however caused and on any theory of liability, whether in contract, 
strict liability, or tort (including negligence or otherwise) arising in any way out of the use of this code, 
even if advised of the possibility of such damage.
*/

echo "Post ID\tPost Type\tPermalink\tFocus Key Word\tPage Title\tMeta Description"; 
include "wp-load.php";

global $wpdb;
$posts = $wpdb->get_results("
SELECT (SELECT `meta_value` FROM `wp_postmeta` WHERE `meta_key` = '_yoast_wpseo_focuskw' AND post_id = wp_posts.ID)  AS focuskw,
(SELECT `meta_value` FROM `wp_postmeta` WHERE `meta_key` = '_yoast_wpseo_title' AND post_id = wp_posts.ID)  AS title,
(SELECT `meta_value` FROM `wp_postmeta` WHERE `meta_key` = '_yoast_wpseo_metadesc' AND post_id = wp_posts.ID)  AS metadesc,
wp_posts.ID, wp_posts.post_type FROM `wp_posts`
WHERE wp_posts.post_status = 'publish'
AND (SELECT `meta_value` FROM `wp_postmeta` WHERE `meta_key` = '_yoast_wpseo_meta-robots-noindex' AND post_id = wp_posts.ID)=0
AND (wp_posts.post_type = 'page' OR wp_posts.post_type = 'post') 
");

header('Content-type:text/plain');
foreach($posts as $post) {

    switch ($post->post_type) {
        case 'page':
            $permalink = get_page_link($post->ID);
            break;
        case 'post':
            $permalink = get_permalink($post->ID);
            break;
        default:
            break;
    }

    echo "\n{$post->ID}\t{$post->post_type}\t{$permalink}\t{$post->focuskw}\t{$post->title}\t{$post->metadesc}";

}

No Replies to "Get Yoast SEO Data"


    Got something to say?

    Some html is OK