[Resolved] Display YouTube videos using GB query loop block.

Home Forums Support [Resolved] Display YouTube videos using GB query loop block.

Home Forums Support Display YouTube videos using GB query loop block.

Viewing 15 posts - 1 through 15 (of 22 total)
  • Author
    Posts
  • #2376764
    Maria

    Does GB Query Loop block work with YouTube videos? Unable to get it to work. I’ve created a CPT for Videos. Using ACF (oEmbed field) and a shortcode in GB Elements Content Template to show video on front end of the single page. Videos display properly. But when I create a Page to display all videos > insert query loop block with same settings as single page, the videos don’t display on the front end. Just wondering if there’s something else I need to show the videos using GB Query Loop block.

    #2376830
    Ying
    Staff
    Customer Support

    Hi Maria,

    This is a core WordPress thing, the same issue will happen on WP’s query loop block.

    The shortcode added to a query loop block will not pull the ID of the current post, it will automatically fall back to the page ID.

    One approach is to use the render_block filter to alter the shortcode block’s content:
    https://developer.wordpress.org/reference/functions/render_block/

    #2376838
    Maria

    So, if I use the render_block filter will the videos now show up on the page I’ve used the Query Loop block with? I’m not a developer so do I just copy and paste the filter as is? Where do I put it, in a Block Element hook?

    #2376859
    Ying
    Staff
    Customer Support

    No, you will need to write your own function first, then use the filter.

    But I think using the GB headline block instead of the shortcode should be able to pull the post meta directly in the query loop.

    Have you tried that yet?

    #2377008
    Maria

    That worked beautifully. Thank you so much.

    #2377828
    Ying
    Staff
    Customer Support

    Glad it works ๐Ÿ™‚

    You are welcome!

    #2430579
    Cris

    Hi

    I’m also trying to make a loop with videos. I used the generateblock loop and it shows the post titles correctly but the video itself (created with CPT) I don’t know how to include it. I tried calling the meta with the image block but it doesn’t work.
    I don’t understand the way you describe here. Can you explain the steps to me?

    #2430639
    David
    Staff
    Customer Support

    Hi there,

    are you using GenerateBlocks Pro ?

    #2430651
    Cris

    No

    #2430710
    David
    Staff
    Customer Support

    Ok – just an FYI the Pro versions supports simple ACF fields out of the box including Oembed.
    Without it you need to use the render_block filter to inject the necessary code.
    This doc shows the code we need from ACF:

    https://www.advancedcustomfields.com/resources/oembed/

    And this is the PHP Snippet to do that:

    
    add_filter( 'render_block', function( $block_content, $block ) {
    	
        if (
            !is_admin() 
            && ! empty( $block['attrs']['className'] )
            && 'acf-oembed' === $block['attrs']['className']
            ){
                $block_content = '<div class="embed-container">' . the_field('oembed') . '</div>';
        }
        
        return $block_content;
    
    }, 10, 2 );

    NOTES:

    1. this line: && 'acf-oembed' === $block['attrs']['className'] – the acf-oembed is CSS Class ( change it to whatever you need ). This gets added to a Headline Block in your query loop. DO NOT set the dynamic data.

    2. this: the_field('oembed') – change the oembed to the name of your field.

    Haven’t tested but it should work …..

    #2430979
    Cris

    It works great! Thank you very much!

    Could an infinite scroll be added?

    #2430991
    David
    Staff
    Customer Support

    Infinite scroll will be a future option in GB Pro.

    Glad to be of help ๐Ÿ™‚

    #2431440
    Cris

    In the loop block I have to indicate how many posts to show per page but how do I change the page after? Is there a pagination?
    I remember seeing it a while ago but now I can’t find it.

    #2431442
    David
    Staff
    Customer Support

    If you select the Query Loop Block, theres an option in the block toolbar to insert the pagination.

    #2431487
    Cris

    I’ve looked everywhere but can’t see it.

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