'I want to fetch backend seo yoast meta

I want to fetch backend seo yoast meta description in wordpress custom post type,but if yoast meta description is empty it should fetch text from tag anybody can suggest how to do it



Solution 1:[1]

You get posts meta by this query:

<?php
    $args = array(
        'post_type'      => 'post',
        'posts_per_page' => -1,
    );
    
    $loop = new WP_Query($args);
    while ( $loop->have_posts() ) {
        $loop->the_post();
    
        $item['seo_meta_description']  = get_post_meta(get_the_ID(),'_yoast_wpseo_metadesc',true);
    
        if(!empty($item['seo_meta_description'])){
           $meta_des = $item['seo_meta_description'];
        }else{
            $meta_des = get_the_content();
        }
    
    }
?>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jahid Hasan