• marekpawlowski

    (@marekpawlowski)


    I am using custom fields and some code I found to display them alongside each entry on the homepage.

    This is the code:

    <?php
          $profile = get_post_meta($post->ID, "profile", true);
    
          //check that we have a custom field
          if ($profile != "")
          {
            // Separate our comma separated list into an array
            $profile = explode(",", $profile);
    
            //loop through our new array
            foreach ($profile as $profil)
            {
              echo $profil;
            }
          }
    ?>

    The custom ‘orofile’ field typically contains quite a lot of text and I’d like to be able to limit the number of words when I display its contents on the homepage.

    Essentially, I’m trying to recreate the way the built-in Excerpt function works, but apply that same idea to custom fields.

    I’ve searched for a plugin or some code to help me do this, but can’t seem to find anything.

    I’d really appreciate any suggestions anyone has. Thanks.

  • The topic ‘Limiting the number of words displayed from custom fields’ is closed to new replies.