Support

Account

Forum Replies Created

  • To put a conclusion on this for others who might come after me — embarrassingly it was me — seems i had historically enabled support for shortcodes in my custom fields using:

    // enables looking for shortcodes in all types of custom fields
    add_filter('acf/format_value', 'do_shortcode');

    There it was sitting in my functions.php but apparently this caused no trouble under php 7 and all the trouble under php 8.

    So i have scoped this filter to the few fields where I know i need it eg:

    // enables looking for shortcodes in all types of custom fields
    add_filter('acf/format_value/name=fancy_footer_content', 'do_shortcode');

    as clearly documented in https://www.advancedcustomfields.com/resources/acf-format_value/

  • Thanks for the quick response. I tried that previously and got the same error, it never executes the print_r because the error is cause when i run get_sub_field.

    Definitely get_sub_field is returning an object. I can go into shortcodes.php and add a print_r and see the object, but only if i run it before lines 212 and and 221 (WP v5.9.3) where $content is evaluated as a string at various points and it fails.

    Like you say it seems unlikely that get_sub_field, which clearly returns an WP Object, should be getting do_shortcode run on it at all. but I can confirm that with no additional code, just me running $postobject = get_sub_field('related_pages'); i get the same error and that i can print_r from the do_shortcode function and see my object returned.

    I’m gonna dig into the ACF configuration and come back here to try describe how these fields relate, maybe i’ve stacked ACF features incorrectly. Also i’m gonna isolate this chunk of code from other wordpress loops etc and see if it’s somehow getting caught up in some other way so it gets run by do_shortcode but any insight deeply appreciated.

  • I have a similar problem it seems. I am using roughly:

    if( have_rows('related_items_list') ):
    			
     	// loop through the rows of data
        while ( have_rows('related_items_list') ) : the_row();
    		echo '<div class="related-item">';	
            // display a sub field value
            $postobject = get_sub_field('related_pages');
    
            echo '<div class="related-item-img" style="background-image: url('. $thumbnail  .')"><a href="'.get_permalink($postobject->ID).'" aria-hidden="true"></a></div>';
    		echo '<div class="related-details"><h3><a href="'.get_permalink($postobject->ID).'">'.$postobject->post_title.'</a></h3>';
    		echo '<div class="related">'.$postobject->post_excerpt.'</div>';
    		echo '</div></div>';	
    		
        endwhile;
    	wp_reset_postdata();
    endif;
    

    and the final error it throws is roughly:

    PHP Fatal error: Uncaught TypeError: strpos(): Argument #1 ($haystack) must be of type string, WP_Post given in .... /wp-includes/shortcodes.php:209

    it does this every time i try to use get_sub_field in a repeater.

    This all worked fine in PHP 7 and is failing in PHP 8

Viewing 3 posts - 1 through 3 (of 3 total)