Home › Forums › Gutenberg › Custom blocks inserted via Gutenberg editor returning JSON › Reply To: Custom blocks inserted via Gutenberg editor returning JSON
Hi,
I had the same issue a few month ago. My solution was similar to yours. I highlighted the search query.
Do you found a way not to specify each block individually?
I have a lot of blocks with individual field names and I don’t want to set every block manually.
Here’s my code:
$content = get_the_content();
$blocks = parse_blocks( $content);
foreach( $blocks as $block ) {
$outercontent = array();
if ($block['blockName'] == 'acf/pagehead') {
$inner = $block['attrs']['data']['content'];
$outercontent[] = $inner;
} elseif ($block['blockName'] == 'acf/andsoon') {
$inner = $block['attrs']['data']['andsoon'];
$outercontent[] = $inner;
}
foreach ($outercontent as $innercontent){
$innercontent = strip_tags( $innercontent );
$keyword = $s;
$keyword = explode(' ',trim($keyword));
$keyword = $keyword[0];
$regex = "/\b" . $keyword . "\w*/i";
if ( preg_match_all( $regex, $innercontent ) ) {
$str = preg_replace( "/\w*$keyword\w*/i", "<b>$0</b>", $innercontent );
$keywordl = strlen( $keyword );
$keywordpos = stripos( $str, $keyword );
$strl = strlen($str);
$str = substr( $str, $keywordpos - 3, 130 );
echo '<li>...'.$str.'...</li>';
}
}
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We’re reaching out to our multilingual users to ask for help in translating ACF 6.1. Help make sure the latest features are available in your language here: https://t.co/TkEc2Exd6U
— Advanced Custom Fields (@wp_acf) May 22, 2023
© 2023 Advanced Custom Fields.
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.