How to use K2 extra fields in our modules

You can use this simple piece of code to load the K2 Extra fields in our K2 modules.

Add this code to the template file of the module:

$extraFld = array();
if ($item->extra_fields) 
{
	$extraFields = json_decode($item->extra_fields, false);
	foreach ($extraFields as $key=>$extraField)
	{
		$extraFld[ $extraField->id ] = $extraField->value;
	}
}

Now you can call a specific extra field by its id. For example:

echo $extraFld[x];

where x is the id of the extra field.

This website uses cookies so that we can provide you with the best user experience. By clicking "continue" you agree to cookies being used in accordance with our Cookies Policy.

Search