Support » Plugins » Hacks » One set of custom meta fields not showing in post

  • Resolved Walton

    (@walton)



    I’m working on a theme for teachers with a custom post type, lesson plan. For example: http://www.englishadvantage.info/testblog/lesson/writing-good-toefl-paragraphs-quickly/

    The info on the right: Goals, Objectives, and Materials are all generated in meta fields I generated. I don’t understand why the Goal is showing, the objectives are showing, but the materials aren’t showing even though there is information there:

    This is the code for that part of the page:

    <div id="goal">
    <?php if (!empty($goal)) echo "<h3>Goal</h3>","<br>",$goal; ?>
    
    <?php if (!empty($objective1)) echo"<h3>Objectives</h3>","<br>","&#149", $objective1;?>
    <?php if (!empty($objective2)) echo "<br>","&#149", $objective2; ?>
    <?php if (!empty($objective3)) echo "<br>","&#149", $objective3; ?>
    
    <h3>Materials</h3>
    <?php if (!empty($materials1)) echo "<br>","&#149", $materials2; ?>
    <?php if (!empty($materials2)) echo "<br>","&#149", $materials2; ?>
    <?php if (!empty($materials3)) echo "<br>","&#149", $materials3; ?>
    <?php if (!empty($materials4)) echo "<br>","&#149", $materials4; ?>
    <?php $args = array(
       'post_type' => 'attachment',
       'numberposts' => -1,
       'post_status' => null,
       'post_parent' => $post->ID
      );
      $attachments = get_posts($args);
         if ($attachments) {
            foreach ($attachments as $attachment) {
               echo "<br>","&#149";
               the_attachment_link($attachment->ID, true);
         }
         };
    ?>
    </div><!--#goal-->

    You’ll see one listing under Materials, but that is being picked up by the attachment loop at the end.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz

    (@bcworkz)

    You mean info on left? In the first echo materials line you are checking if $materials1 is empty but then trying to echo $materials2, the two variables should match, both ending in 1, not one with 2. I’m guessing $materials1 was the only one defined? If the others were defined, I don’t know what the problem is.

    Oops. I did fix that. But it’s still not working. And yes materials1, materislas2 and materials3 are all defined. Every time I load the Edit Lesson Page, they are populated. I don’t get it.

    Moderator bcworkz

    (@bcworkz)

    I had a feeling that was too easy.

    Well, there’s nothing wrong with the posted code. The code that populates the edit form fields is not the same that assigns $materials1 etc. The problem could be in that assignment, or something along the way between assignment and echo, a name conflict, or scope issue perhaps.

    Try using something like error_log("Location description: $material1"); at strategic points to find out where the value disappears. Assuming you have access to the error logs of course.

    It was almost easier. Going through adding the error log code, I discovered that I never called for the materials values in the lesson plan! I never did get_post_custom.

    Thanks for the step that got me there!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘One set of custom meta fields not showing in post’ is closed to new replies.