I am trying the same or similar php function inside the bricks-builder
function brx_count_h2_tags($post_id, $mb_field) {
$post_content = rwmb_get_value( $mb_field , '', $post_id );
preg_match_all("/<h2.*?>.*?<\/h2>/i", $post_content, $matches);
echo 'number of h2 tags: ' . count($matches[0]);
}
brx_count_h2_tags( 3311 , 'html_post' );
... and alternatively in WPCodeBox2:
function brx_count_h2_tags( $post_id , $mb_field ) {
$post_content = rwmb_get_value( $mb_field, '', $post_id );
// Use preg_match_all to find all <h2> tags
preg_match_all('/<h2.*?>.*?<\/h2>/i', $post_content, $matches);
return count($matches[0]);
}
Where running the code inside the builder it works fine (shows a number) BUT the latter throws an error:
**Error Message:**
syntax error, unexpected token "<"
**On line:** xxx
**Error Trace:**
#0 /home/main/public_html/xxx/wp-content/plugins/wpcodebox2/src/Service/WPCodeBox2.php(124): Wpcb2\Runner\QueryRunner->runQueries() #1 /home/main/public_html/xxx/wp-content/plugins/wpcodebox2/wpcodebox2.php(58): Wpcb2\Service\WPCodeBox2->executeSnippets()
I have no idea what the reason for this is.
Any ideas?