• Resolved jalacom

    (@jalacom)


    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>'; with the_meta() something or other?

    Thanks in advance for any help!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter jalacom

    (@jalacom)

    I had the line wrong I would have to make changes here:
    echo '<li class="recipelist"><a href="'.get_permalink($post->ID).'">'.get_the_title($post->ID).'</a>'. $speaker_name . $scripture.'';

    And it looks like I have some extra stuff I need to remove there such as $speaker_name . $scripture. It’s content from the original code snippet I found from someone else.

    So I did this:
    echo '<li class="recipelist"><a href="'.get_permalink($post->ID).'">'.get_post_custom_values($recipe).'</a>';
    The link is being generated when I inspect the element in the browser, but it’s not echoing out the name of $recipe.

    What am I doing wrong?

    Thread Starter jalacom

    (@jalacom)

    figured it out:
    echo '<li class="recipelist"><a href="'.get_permalink($post->ID).'">'.get_post_meta($post->ID, 'recipe', true).'</a>';

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to display a Custom Field name’ is closed to new replies.