How to display a Custom Field name
-
Hi,
I’m trying to display a custom field in a list. What I have currently is a page called Recipes. Currently if I select the category Recipe and a Subcategory in recipes such as Breakfast Ideas it will display my posts title in the list of recipes with the appropriate Subcategory as a section header. recipes page
Which is great. However currently I have a lot of posts that contain a recipe however the title of the post is not the title of the recipe. So instead of getting the name of the recipe in my list I get the name of the post. How would I create a custom field for each of these posts and any new posts I create and use it to populate the list of recipes with the appropriate title.
So for instance I have a post called “The ReDux Challenge For March Maple Syrup”. I want the recipes page to display this post under Breakfast Ideas (which it does no problem) and I want to use a custom field so the name that appears is Maple Syrup.Here’s my current code.
<?php $categories = get_categories('child_of=5'); foreach ($categories as $category) { echo '<h2>'.$cat_img.$category->name.'</h2>'; // start a list for the recipes echo '<ul>'; foreach (get_posts('orderby=post_date&category='.$category->term_id) as $post) { setup_postdata( $post ); // echo out the results into a list item echo '<li class="recipelist"><a href="'.get_permalink($post->ID).'">'.get_the_title($post->ID).'</a>'. $speaker_name . $scripture.''; } // close the list echo '</ul>'; } ?>
I’m assuming I need to replace this line
echo '<h2>'.$cat_img.$category->name.'</h2>';
withthe_meta()
something or other?Thanks in advance for any help!
- The topic ‘How to display a Custom Field name’ is closed to new replies.