get custom field value wordpress code example

Example 1: get custom field

/* put this code in home.php file create in child theme  */

<?php 
 /*Template Name: Home Template*/
 
echo get_post_meta($post->ID, 'Name', true); 
  
?>
 /* Or use this code  */
 <?php 
	$value =get_field('Name');
	echo $value;
?>

Example 2: get field acf

$content = get_field('content', $post_id);

Example 3: wp display custom fields

<?php
// assign variables for each custom field
$your_custom_field_name1 = get_post_meta(get_the_ID(), 'your_custom_field_name', true);
$your_custom_field_name2 = get_post_meta(get_the_ID(), 'your_custom_field_name', true);

// if is not empty, echo html
if (!empty($your_custom_field_name1)) {
    echo '<h3>Label: ' . $your_custom_field_name1 . '<h3>';
    }
if (!empty($your_custom_field_name2)) {
    echo '<p>ISBN: ' . $your_custom_field_name2 . '</p>';
}
?>

Example 4: custom fields wordpress

/*  Wordpress  for custom field -------
 create template file like home.php and add this code  */

<?php echo get_field('name');?>

Tags:

Php Example