• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

WP SITES

2665

Original Genesis Tutorials & 5000+ Guaranteed Code

Snippets

  • Support
  • Newsletter
  • Videos
  • Log in

Premium Member? - Request custom code

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:

Register for full access

Custom Fields

Reader Interactions

Comments

  1. kemahbreeze says

    July 28, 2017 at 10:29 am

    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).

    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: <strong>%s</strong>Scientific Name: <strong>%s</strong>Family: <strong>%s</strong>Warm/Cool: <strong>%s</strong>Plant Usage: <strong>%s</strong>Taste: <strong>%s</strong>Yin/yang: <strong>%s</strong>Energetics: <strong>%s</strong>Actions: <strong>%s</strong>', $comname, $sciname, $family, $temp, $parts, $taste, $yinyang, $energetics, $actions );
    
        return $output;
    }

    Thanks!
    Terry McDonald (kemahbreeze)

    Log in to Reply
    • Brad Dalton says

      July 28, 2017 at 9:16 pm

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

      Log in to Reply
      • kemahbreeze says

        July 29, 2017 at 11:23 am

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

        Thanks,
        Terry

        Log in to Reply

Leave a Reply Cancel reply

You must be logged in to post a comment.

Primary Sidebar

PHP Code

template_include

get_body_class

if else

array

class_exists

foreach

sprintf

add_action

printf

variable

Advertise · WPEngine · Genesis · Log in

  • How Premium Membership Works
  • Sign Up
  • Support
  • Subscription Details/Invoice
  • Tagged Tutorials
  • Access-Download Problems