• Resolved Tomoki Shimomura

    (@shimotomoki)


    I’m trying to access metadata that is no longer working in the new version by referring to this topic
    https://www.ads-software.com/support/topic/certain-tag-of-description-isnt-renewed/

    Is there any way to get and display the meta description in the top page loop?
    If I do the following, the description of the top page will be displayed.

    if ( have_posts() ) {
      while ( have_posts() ) {
        the_post();
        $post_id = get_the_ID();
        $get_post = get_post($post_id);
        echo aioseo()->meta->description->getDescription($get_post);
      }
    } 

    I also looked at the functions for getDescription, but they don’t seem to take into account displaying it in the loop.

    Also

    echo aioseo()->meta->metaData->getMetaData($post)->description;

    it shows the description in unencoded form, such as #post_excerpt.
    How can I fix this?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author arnaudbroes

    (@arnaudbroes)

    Hey @shimotomoki,

    Try this –

    echo aioseo()->meta->description->getPostDescription($get_post);

    Let me know if that works.

    – Arnaud

    Thread Starter Tomoki Shimomura

    (@shimotomoki)

    Thanks for the reply!
    Then it’ll work in a loop!

    I just can’t get the empty or not empty condition to work anymore.

    //All in One SEO Pack 4.0 Before
    if (!empty(get_post_meta($post->ID, '_aioseop_description', true))) {
      $meta_description = get_post_meta($post->ID, '_aioseop_description', true);
    }
    
    //All in One SEO 4.0 After
    if (function_exists('aioseo')) {
      $aioseo_description = aioseo()->meta->metaData->getMetaData($post)->description;
      if(!empty($aioseo_description)) {
        $meta_description = $aioseo_description;
      }
    }
    echo $meta_description;

    The above code works fine.

    //All in One SEO 4.0
    if (function_exists('aioseo')) {
      $post_id = get_the_ID();
      $get_post = get_post($post_id);
      $post_description = aioseo()->meta->description->getPostDescription($get_post);
      if (!empty($post_description)){
        $meta_description = $post_description;
      }
    }
    echo $meta_description;

    However, if you use getPostDescription, you won’t be able to determine if it’s empty or not.

    Thread Starter Tomoki Shimomura

    (@shimotomoki)

    sorry
    I was able to solve it.

    //All in One SEO Pack 4.0 Before
    if (!empty(get_post_meta($post->ID, '_aioseop_description', true))) {
      $meta_description = get_post_meta($post->ID, '_aioseop_description', true);
    }
    //All in One SEO 4.0 After
    if (function_exists('aioseo')) {
      $aioseo_description = aioseo()->meta->metaData->getMetaData($post)->description;
      if(!empty($aioseo_description)) {
        $post_id = get_the_ID();
        $get_post = get_post($post_id);
        $meta_description = aioseo()->meta->description->getPostDescription($get_post);
      }
    }
    Plugin Author arnaudbroes

    (@arnaudbroes)

    Awesome!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Is there a way to get and display the meta description in the top page loop?’ is closed to new replies.