After hours of googling I came up with following solution. Maybe once will help to someone.
1) query post where is used gutenberg youtube block:
$args = array(
'post_type' => 'post',
'post_status' => 'publish',
's' => 'core-embed/youtube',
'posts_per_page' => 1
);
$query = new WP_Query($args);
2) extract the URL from youtube block of the post
$post_id = 117;
$post = get_post($post_id);
$blocks = parse_blocks( $post->post_content );
function findYoutubeBlock(array $blocks) {
return $blocks['blockName'] == 'core-embed/youtube';
}
if (has_block('core-embed/youtube', $post_id)) {
$youtube_block = reset(array_filter($blocks, 'findYoutubeBlock'));
$youtube_url = $youtube_block['attrs']['url'];
}
Related Posts:
- Using pre_get_posts on a specific core/query block
- How to query for custom field within Gutenberg block from outside of that post? [closed]
- While creating Block Themes in WordPress, how can I query custom posts for an Archive view?
- Creating query to show which editor (classic or block) was last used to edit a post/page
- Is it possible (and how to) query single Gutenberg blocks?
- Block Editor – WordPress 6.1 – CPT Archive Issue – While the title changes in the loop, all records display the same data
- query loop “inherit query from template” prevents setting sort order
- How to display page content in a page template?
- Display List Of Posts Containing a Relationship Field Value [ACF]
- What to do in this case after wp_query has been modified
- Get the number of posts from the current page results
- How to get random posts and order them by date
- When should you use wp_reset_postdata vs wp_reset_query?
- WP API to fetch all the media/posts records if count is more than 100
- How to order posts by custom WP role?
- Generate a tabbed submenu — from taxonomy term or submenu item — with sample content
- posts2posts query using connected_items array issue [closed]
- Explanation of WP_Query
- Display revision if post status is pending
- Meta query field order together with post_date order causes posts without the meta field to be unordered
- How To Remove/hide some specific categories from two different categories widget from sidebar
- WP Query search for attachments and their exact title
- Undefined property: WP_Query::$post
- Excluding Sticky Posts from The Loop and from WP_Query() in WordPress?
- How to display posts month by month?
- Query different number of posts with different formats in one go
- Extending woocommerce admin product search
- Pagination is broken and I need help fixing it
- How to display a posts 1 year ago with custom WP_Query loop?
- need to exclude APP_TAX_STORE => $term->slug
- Check on which page specific result exist
- Loop returning only 1 result
- Fetch posts that match term slug first two letters (wp query)
- How can I use $wp_query->tax_query as tax_query parameter for a new WP_Query instatiation?
- How does one perform a sub query with different post types
- Query with search and subscribers only output
- Post loop for all taxonomy terms
- Pre-Populate $wp_query settings with custom rewrite rules and custom template_redirect
- exclude a post from wp_query loop
- Is_single() conditional tag returns null in query
- Is it possible to query a custom field where the value is between two fields?
- WP_Query args to show posts from specific custom taxonomy
- How to query woocommerce product by pricing? [closed]
- filter wp_query result with custom field values
- Posts in loop all show the same author when there are many authors
- Show a 404 error page if Public query variable’s value doesn’t exist?
- WP_Query within function within WP_Query
- If have posts a week old, display, else display a different loop
- All blog data on a page using custom query gives 404 for page 2 and onward
- Daily drip of posts – based on user ‘startData’ – ordered oldest to newest
- How to add tax_query to $args with concatenation
- construct complex queries with WP User Query
- How do I fit WP_Query arguments into a function?
- Create one-use post dynamically, add to main query, do not insert post (user profile view)
- Pagination problem by using WP_Query
- Why always one post missing
- Is there ANYTHING about this query that’s incompatible with WordPress 2.9.2?
- get all images from the wordpress media library with link to the post they are associated with
- Add metabox if there is at least one post available
- Custom Taxonomy – Modify Function to Get Child Category
- WP Query – grouping posts by same meta key, adding together values from another key
- setting offset to category number in archive page
- Retrieve all custom field values of a specific custom field metakey as an array, inside WP_Query
- Pass post ID to JavaScript outside the loop
- Query for current post
- Access queried post ID in WP_Query
- Loop through array of pages
- Query Posts | Combining multiple form inputs into query arguments to generate one filter result
- Filtering posts for unique titles, only the most recent
- How to show post title in content editor in backend?
- List users by Year of Birth using a foreach loop to dynamically populate years and data
- Query_post 5 post first / last of post_id
- View related categories in order of posts
- query only returning posts with already set custom field
- Using URL variables on a custom WP_Query
- Sorting posts by meta values: 2 different orders
- Escaping WP_Query tax_query when term has special character(s)
- How to get hierarchical number of custom taxanomy
- Show parent’s child and also child’s, child on a page?
- Show posts in category
- Is there any difference between below WP_Query code snippets?
- Order by three custom fields (Y-m-d), then separate into yearly sections
- Both WP_Query and get_posts returning 1 post
- Using WP_Query to re-query and sort results using a date?
- wordpress query from multiple post id
- Get the tax term in which is a post via wp_query
- Using WP_Query to get attachment returns empty set
- wp_query display posts based on day
- meta_query compare not doing what I want it to do
- Displaying specific posts from query thumbnail outside div
- WordPress query very slow on +/- 300k DB entries and 7 INNER JOIN
- How to display only top posts of parent categories in loop via WP_Query?
- Empty query on Custom Post Type, using WP_Query or get_posts
- Give attachments an archive page, and exclude unattached ones
- The permalink redirecting to current article on single.php page
- Variations as Single Products [closed]
- Bulk delete comments, foreach loop
- Group users by meta field, with name of meta field as group title
- How do I group results from wp-query
- How could i add username field in WooCommerce