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.

For an alternative method, check out this article.

This website uses cookies to ensure that you get the best user experience. Cookies Policy / Privacy Policy

Search