• Resolved csleh

    (@csleh)


    My goal is for $related to be used if any of the sub_fields are populated.

    $topic_tags = get_sub_field('topic_related_tags');
     $topic_post = get_sub_field('related_post');
     $topic_page = get_sub_field('related_page');
    	  $related = (strlen($topic_tags) + strlen($topic_post) + strlen($topic_page ) >0)?true:false;

    Using
    $related = (isset($topic_tags) && isset($topic_post) && isset($topic_page ))?true:false;
    results as true even if there aren’t any sub_fields.

    But using (strlen()) gives an error where the title will go.
    “Warning: strlen() expects parameter 1 to be string, array given…”

    obviously I’m not a php coder but I have exhausted my google skills trying to figure it out.

Viewing 1 replies (of 1 total)
  • Thread Starter csleh

    (@csleh)

    Did not exhaust google skills after all!

    I had to switch to if not empty. so this works:

    <?php
        	$topic_tags = get_sub_field('topic_related_tags');
        	$topic_post = get_sub_field('related_post');
        	$topic_page = get_sub_field('related_page');
    	 if (!empty($topic_tags) || !empty($topic_post) || !empty($topic_page )) {
    			echo '<h4>My title</h4>';
    			} ?>

Viewing 1 replies (of 1 total)
  • The topic ‘help to fix php error: strlen() expects parameter 1 to be string, array given’ is closed to new replies.