error in WPCodebox2 but not in Bricksbuilder fontend.

Support General error in WPCodebox2 but not in Bricksbuilder fontend.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #46839
    jw_blnjw_bln
    Participant

    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?

    #46843
    PeterPeter
    Moderator

    Hello,

    Maybe the issue happens when you use the regex function but the function rwmb_get_value() returns an empty value. You should check the value isn't empty before executing the regex function.
    Besides that, it isn't an issue of Meta Box itself so if you still have an issue when using the regex function, please contact an expert developer to help you in this case.

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