Adding custom fields to WordPress posts is a common necessity, complementing the platform’s built-in features like tags and featured images.
While, WordPress offers robust functionality, custom fields enhance it by accommodating additional information tailored to specific needs. This could include diverse content such as text, images, links, or more complex data. Utilizing the default custom field functionality in WordPress provides a flexible solution, enabling users to extend their site’s capabilities without the need for extensive coding or plugins.
Whether for personalization, integration with external systems, or enhancing user experience, custom fields are invaluable in enriching WordPress content beyond its default offerings.
You have to follow the below step to add the custom fields & to get the custom field value in the code ( to get in the template files example header, footer, content, content top etc )
Step 1: Login to wordpress Admin
Step 2: Left menu “All Post”
Step 3: Click on “Edit” button to edit the post and on which you want to add custom field
Step 4: Now, click on the right side top 3 dots, check below image indication
Step 5: Once you click on “Preferences” a pop will option and it will provide option to enable “Custom fields”
Step 6: Enable it and click on “Show & Reload Page” button, a section to add the values will be appeared below:
Step 7: Now, lets put the “Status” in the name input and in Value add “Active” for this hello world post.
You will also get the option to delete or update
So, this how you are going to add the “Custom Field” Now, let us tell you how you are going to retrieve/get this field.
<?php
echo get_post_meta( get_the_ID(), 'Status', true );
echo '<br />';
echo get_post_meta( get_the_ID(), 'date', true );
?>
From the array you can do it.
my_key - Your custom field name.
$mykey_values = get_post_custom_values( 'my_key' );
foreach ( $mykey_values as $key => $value ) {
echo "$key => $value ( 'my_key' )<br />";
}
0 => First value ( 'my_key' )
1 => Second value ( 'my_key' )
2 => Third value ( 'my_key' )
If you still find any problem you can drop a comment and will surly get back to you in few hours. Also, you can drop us email at info@purchasetheme.com