I am modifying a search.php template. The basic template displays search results with thumbnail, title, date, and author. I would like to add 2 additional fields from the wp_metadata table. I assume I need to write a function and add it to my child theme functions.php file, then call the function from the template. I just need to know how to correctly write the function.
You need to use
get_post_meta( $post_id, $key = '', $single = false )
Retrieve post meta field for a post
$post_id (int) (Required) Post ID.
$key (string) (Optional) The meta key to retrieve. By default, returns data for all keys. Default value: ''
$single (bool) (Optional) Whether to return a single value. Default value: false
echo get_post_meta( $post->ID, 'the-name-of-key', true);
true, you will get a
string, but if you use
false instead, you will get an