infoscigeek
8/16/2017 - 7:38 AM

From https://deanandrews.uk/get-yoast-seo-data/

 <?php
/**
 * Version: 3.0
 * Date: 02/11/2016
 * Source: https://deanandrews.uk/get-yoast-seo-data/
 * 
 * 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.
 */

// Get the key data from the URL
function CheckAccess(){
  return @$_GET['key']=='MySecretKEY';
} 

// If the key is incorrect block access to data
if (!CheckAccess()){
  header('HTTP/1.0 404 Not Found');
  exit;
}

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 `$wpdb->postmeta` WHERE `meta_key` = '_yoast_wpseo_focuskw' AND post_id = $wpdb->posts.ID)  AS focuskw,
(SELECT `meta_value` FROM `$wpdb->postmeta` WHERE `meta_key` = '_yoast_wpseo_title' AND post_id = $wpdb->posts.ID)  AS title,
(SELECT `meta_value` FROM `$wpdb->postmeta` WHERE `meta_key` = '_yoast_wpseo_metadesc' AND post_id = $wpdb->posts.ID)  AS metadesc,
$wpdb->posts.ID, $wpdb->posts.post_type FROM `$wpdb->posts`
WHERE $wpdb->posts.post_status = 'publish'
AND (SELECT `meta_value` FROM `$wpdb->postmeta` WHERE `meta_key` = '_yoast_wpseo_meta-robots-noindex' AND post_id = $wpdb->posts.ID)is null
AND ($wpdb->posts.post_type = 'page' OR $wpdb->posts.post_type = 'post') 
");

header('Content-type:text/plain');
foreach($posts as $post) {
	$permalink = get_permalink($post->ID);
	echo "\n{$post->ID}\t{$post->post_type}\t{$permalink}\t{$post->focuskw}\t{$post->title}\t{$post->metadesc}";
}