1. Home
  2. ReHub Theme
  3. Advanced tips and customizations
  4. How to get any custom field or attribute value and show in theme

How to get any custom field or attribute value and show in theme

To get value of meta field use this magic shortcode:

[wpsm_custom_meta field="META-KEY-NAME" label="My label:" show_empty=1 posttext="after value text" icon="" list="" type=""]

Where can you use this shortcode? Well, it’s really powerful feature with unlimited possibilities. You can use it to show some featured attribute values in Product loops and on inner pages (use it inside Custom product areas). You can use it in Posts areas in Theme option – ads option to show some additional info for posts

You can even get meta values of Author of post (for example, can be useful if you want to show Phone or Contacts of Author of Post on Post page)

Let’s check parameters.

Label

If you don’t need label – delete label parameter. Label is just test string which will be available before value.

posttext

The same as label, but this text will be visible after value.

field

Most important part. Must include name of custom or user field or attribute.

icon

Add classes of icons (get them in Fontawesome site) in icon parameter. You can copy classes from each icon

Example of code with these icons

[wpsm_custom_meta field="META-KEY-NAME" icon="fas fa-abacus"]

Icons will be visible before value. You can add also class mr5 or mr10 if you want to add some margin between value and icon.

[wpsm_custom_meta field="META-KEY-NAME" icon="fas fa-abacus mr5"]

For left margin, use ml5 or ml10

show_empty

By Default, if your custom field doesn’t have value, shortcode does nothing and empty space will be returned. Set show_empty=1 if you want to show symbol “-” for empty values

list

By default, values will be visible as simple text. If you want to show it as bullet list, add list=1. You must also wrap whole code with ul tags. Example

<ul>

[wpsm_custom_meta field="META-KEY-NAME" list=1]

[wpsm_custom_meta field="META-KEY-NAME-2" list=1]

</ul>

type 

This will get different type of data. By default, shortcode will grab custom field value.

 type=author  – it will get user meta field of post author.

 type=attribute  will get woocommerce attribute value.

 type=attributelink  will get attribute values and show them as links to attribute archive pages.