Are you a GenerateCustomer?

Do you have an active GP Premium or GenerateBlocks Pro license key?

Create a GenerateSupport account for GeneratePress and GenerateBlocks support in one dedicated place.

Create an account
Already have a GenerateSupport account? Login

Just browsing?

Feel free to browse the forums. Support for our free versions is provided on WordPress.org (GeneratePress, GenerateBlocks).

Want to become a premium user? Learn more below.

Query Loop and Post Meta Description

  • Hello,

    I have created a Query Loop in a specific page so it can show my last 10 posts I have made from a specific category of posts.

    In each post of this Query I have added the featured image, the title, the category of the post and information about the author. Everything looks great so far. One thing that I cannot add is the post’s meta description.

    What I have done is I added a Headline and enabled the Dynamic Data option. For Data Source I chose current post and Content Source Post Meta. But in the Post Meta list there is nothing to choose. It shows empty.

    What am I doing wrong?

  • Hi Stratos,

    What “description” meta is this? Is it a custom meta you added? If so, try to add its slug in the field name manually.

  • In the end of the block editor there are the AIOSEO settings with fields for Meta Title and Meta Description.

    This Meta Description is the one I want to add.

  • That seems to be from a plugin. Can you check? If not, can you share a screenshot?

  • It’s from the All in One SEO plugin I believe. Is it possible to get the Meta Description from it to display in the Query Loop?

  • Hi there,

    display All In One SEO AISEO Meta Description using dynamic data.

    for reference i found this topic where the user provides some code to get the AIOSEO meta description:

    https://wordpress.org/support/topic/is-there-a-way-to-get-and-display-the-meta-description-in-the-top-page-loop/#post-14205463

    We should be able to repurpose that.

    1. Add this PHP Snippet to your site:

    
    add_filter( 'render_block', function( $block_content, $block ) {
        if ( 
            !is_admin() && 
            function_exists('aioseo') &&
            ! empty( $block['attrs']['className'] ) && 
            strpos( $block['attrs']['className'], 'seo-description' ) !== false 
        ) {
            $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);
                return $meta_description;
            }
        }
        return $block_content;
    }, 10, 2 );

    2. Add a Headline block with some static text to your query loop and in its Advanced > Additional CSS Class(es) add: seo-description

  • Success! It works great! Thank you very much for the help!

  • Glad to hear that!

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.