4 Ways To Output Multiple Custom Field Values Inline

These 3 code snippets all produce exactly the same result on the front end:

custom-fields

The code enables you to display the value of all custom fields in 1 line. There’s no need to use CSS for this solution as it can all be done using PHP code. You can also use the 3rd example to style each value differently.

The 4th example creates a shortcode you can use in the WordPress editor or anywhere that shortcodes can be parsed like a text widget.

The code examples include solutions which work in any WordPress theme & solutions which only work in Genesis child themes.

Here’s the code:


Comments

3 responses to “4 Ways To Output Multiple Custom Field Values Inline”

  1. kemahbreeze Avatar
    kemahbreeze

    Hi,
    Thanks for a great resource! I am using this method to create a shortcode for a sidebar widget. It’s working perfectly except that two of my fields are arrays. How can I display these two fields with commas separating each item in each array? Here is what I have so far (energetics and actions are the two array fields).
    [code]
    function multiple_custom_fields_inline4() {

    $comname = sprintf( ‘%s’, genesis_get_custom_field( ‘common_names’ ));
    $sciname = sprintf( ‘%s’, genesis_get_custom_field( ‘scientific_name’ ));
    $family = sprintf( ‘%s’, genesis_get_custom_field( ‘plant_family’ ));
    $temp = sprintf( ‘%s’, genesis_get_custom_field( ‘herb-temp’ ));
    $parts = sprintf( ‘%s’, genesis_get_custom_field( ‘medicinal_plant_part’ ));
    $taste = sprintf( ‘%s’, genesis_get_custom_field( ‘taste’ ));
    $yinyang = sprintf( ‘%s’, genesis_get_custom_field( ‘yin_or_yang’ ));
    $energetics = sprintf( ‘%s’, genesis_get_custom_field( ‘energetics’ ));
    $actions = sprintf( ‘%s’, genesis_get_custom_field( ‘actions’ ));

    $output = sprintf(‘
    Common Name: %sScientific Name: %sFamily: %sWarm/Cool: %sPlant Usage: %sTaste: %sYin/yang: %sEnergetics: %sActions: %s‘, $comname, $sciname, $family, $temp, $parts, $taste, $yinyang, $energetics, $actions );

    return $output;
    }
    [/code]
    Thanks!
    Terry McDonald (kemahbreeze)

    1. Brad Dalton Avatar
      Brad Dalton

      Hi Terry. I would like to help you with this question however i don ‘t fully understand what you are trying to do.

      1. kemahbreeze Avatar
        kemahbreeze

        Hi Brad,
        Never mind. I worked it out. I used implode() to turn the arrays into strings.

        Thanks,
        Terry

Leave a Reply

Join 5000+ Followers

Get The Latest Free & Premium Tutorials Delivered The Second They’re Published.