[resolved] explode custom field not working (3 posts)

  1. wassem mansour
    Posted 2 years ago #

    i am trying to use this code to explode data from custom field by name (schools) which includes data like : one,two,three
    but it keeps returning this error

    Warning: trim() expects parameter 1 to be string, array given in C:\xampp\htdocs\***\wp-content\themes\***\schools.php on line 20

    anyhelp ?

    <div class="schools_names">
    		$school = get_post_meta($post->ID, 'schools', false);
    		$school = explode(',' , $school);
    		foreach($school as $src)
    		echo '<a href="#" target="_blank">'.trim($src).'</a> - ';
  2. alchymyth
    Forum Moderator
    Posted 2 years ago #


    using 'false' as the third parameter ($single) would return an array:

    If false, or not set, then the function returns an array of the custom fields.

    if you have just a string with comma-separated words in your custom field, try to set that parameter to 'true'.

  3. wassem mansour
    Posted 2 years ago #

    yes thank you , Worked perfect.

Topic Closed

This topic has been closed to new replies.

About this Topic