Programmatically change the content of the list items


In this tutorial, you’ll see how to programmatically change the list items content so you can display complex content such as shortcodes, array custom fields, taxonomies, etc…

Edit the file “functions.php” of your theme/child theme and copy/paste the exemplary code below, then, adapt it to your needs:

$post_id: The ID of the post. Use it to get your post data.

$default_content: The default list item content .

function cspml_custom_item_description($default_content, $post_id){
	
	$custom_content = '';
	
	$name_custom_field = get_post_meta($post_id, "YOUR_CUSTOM_FIELD_NAME", true);
	$address_custom_field = get_post_meta($post_id, "YOUR_CUSTOM_FIELD_NAME", true);
	$website_custom_field = get_post_meta($post_id, "YOUR_CUSTOM_FIELD_NAME", true);		
	
	$custom_content .= '<strong>Name: </strong>' . $name_custom_field. '<br />';
	$custom_content .= '<strong>Address: </strong>' . $address_custom_field . '<br />';
	$custom_content .= '<strong>Website: </strong><a href="'.$website_custom_field.'">Visit</a>';
	
	return $custom_content;
 
} 
add_filter('cspml_item_description', 'cspml_custom_item_description', 10, 2); 

In the same context