• I’ve simply added a custom field called “description_heading” with a value of “Find and rate agents now.”

    However, When I go into the template and add:

    <p class="description_heading">
     <?php echo get_post_meta($post->ID, 'description_heading', true); ?>
     </p>

    Nothing is displayed. I plugged in an arbitrary “Print this” in front of the echo and it displayed in the template so it is something with the get_post_meta call that isn’t working. Am I missing something? Not sure what the problem is.

    On another note, I have another install that is version 3.3.2 and the same code is working just fine, although it is in a different theme. Not sure that would matter but it is 3.4 where I’m having the problem.

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

    (@dscouron)

    Think I’ve figured this out. For anyone who has similar issues in the future, I believe that the solution has to do with whether or not you are using the:

    get_post_meta($post->ID, '$key', true);

    within The Loop. For anyone experiencing similar problems, I have found that changing $post->ID to get_the_ID() if you are outside the loop should do the trick.

    Hey guys,

    I’m actually having this same problem. The only difference (and reason why the solution here doesn’t work) is that my get_post_meta() is located inside a loop. Both get_the_ID() and $post->ID do not work in either case. Everything was working prior to upgrading to 3.4. The template that contains this code is very custom to build out a list of available classes and course topics. Here’s a sample, hopefully it’s enough to try and help me:

    if (have_posts()) : while (have_posts()) : the_post();
    
        	             $ClassroomDates = get_post_meta($post->ID, "classroom_date", false); 
    
        		         foreach($ClassroomDates as $individual_classroom_date) {
    
        		             $first_date = substr($individual_classroom_date, 0, 10);
    
        		             echo "<tr>";
    
        			             echo "<td>CLASSROOM</td><td>"; ?>
    
        			             <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a>
    
        			         <?php
        			             echo "</td>";
    
        		                 echo '<td>'.$first_date.'</td>';
    
        		                 echo '<td>';
    
        		                 echo get_post_meta($post->ID, "duration", true);
    
        		                 echo '</td>';
    
        		                 echo '<td class="price-cell">'; ?>
    
        		                 <?php echo '$'; echo get_post_meta($post->ID, 'price', true); ?>
    
        		                 <?php 
    
        		                 echo '</td><td>';
    
        		                echo '<form class="foxycart" action="https://envision.foxycart.com/cart" method="post" accept-charset="utf-8">
    
    <input type="hidden" name="name" value="'; ?>
    
                                <?php the_title(); echo " - $individual_classroom_date - Classroom"; ?>
    
                                <?php echo '" />
    <input type="hidden" name="price" value="'; ?>
    
                                <?php echo get_post_meta($post->ID, 'price', true); ?>
    
                                <?php echo '" />
    
    <input type="submit" value="Register" class="submit" />
    </form>';
    
        	                 echo "</td></tr>";
        	             }

    If you can help me shed any light on this, that would be great. It’s for a client that needs it working, thank you!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Problem With Custom Fields’ is closed to new replies.