简体   繁体   中英

I want to fetch backend seo yoast meta

我想在 wordpress 自定义帖子类型中获取后端 seo yoast 元描述,但如果 yoast 元描述为空,它应该从标签中获取文本,任何人都可以建议如何做

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();
        }
    
    }
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM