Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter downfast

    (@downfast)

    whoops…forgot to add the code tags

    <?php $pages = get_pages('child_of='.$post->ID.'&sort_column=post_date&sort_order=desc&parent='.$post->ID); $count = 0; foreach($pages as $page) { $content = $page->post_content; if(!$content) continue; if($count >= 2) break; $count++; ?>
    
    <div class="thumb">
    ID) ?>"><h1 class="title"> <?php echo $page->post_title ?> </h1>
    <?php echo $page->post_content ?>
    </div>

    Try putting this code after <?php echo $page->post_content ?> and before your last </div>. It will get the custom fields (the meta) and print them out as key/value pairs.

    <?php
    
      $custom_fields = get_post_custom($page->ID);
      $my_custom_field = $custom_fields['my_custom_field'];
      foreach ( $my_custom_field as $key => $value )
        echo $key . " : " . $value . "<br />";
    
    ?>

    This is from http://codex.wordpress.org/Function_Reference/get_post_custom

    Hope that helps.

    Thread Starter downfast

    (@downfast)

    thanks but i get this:

    Warning: Invalid argument supplied for foreach() in C:\wamp\www\mandc\wp-content\themes\mandc\thumb.php on line 24

    where line 24 is where i have inserted that code (just before the closing div).. any idea?

    Oops, looks like that code was to get all the values for the key ‘my_custom_field’.

    This code here will get the first value of each key. This should be pretty similar to the_meta() but you can use out of the loop. Try using this instead of the previous code, and put it in the same spot as before.

    <?php
    
      $custom_fields = get_post_custom($page->ID);
    
      foreach ( $custom_fields as $key => $value )
        echo $key . " : " . $value[0] . "<br />";
    
    ?>

    Thread Starter downfast

    (@downfast)

    hey thanks a lot, i think it’s getting closer but not quite there yet..

    it is now getting the “low season” which is the name of my custom field, but also displaying other info..

    Low season : Array
    _edit_lock : Array
    _edit_last : Array
    mf_page_type : Array
    _wp_page_template : Array
    _cspc-page-transitions : Array

    Hi, you’re welcome. If you’d like to just display the value of your custom field “low season” you can use this function:

    <?php $key_1_value = get_post_meta($page->ID, 'Low season', true);
    print $key_1_value; ?>

    (From http://codex.wordpress.org/Function_Reference/get_post_meta)

    Otherwise, looks like pages have a lot of extra custom field data there. You could skip those keys, excluding them from the output, or rather just target the specific meta you want. Depends on what you plan on putting into the page custom fields (meta) and what you want to output.

    Thread Starter downfast

    (@downfast)

    that’s it! that is exactly what I was looking for.
    yes it had more custom fields, but i wanted to only target one of them, basically i am building a page with thumbs of the sub pages and i needed to get part on the info in each thumb.

    Anyway..thanks a lot! 🙂

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘get the informartion form the_meta of a sub page’ is closed to new replies.