Title: Display Custom Fields posts on static page
Last modified: August 19, 2016

---

# Display Custom Fields posts on static page

 *  [digitalminds](https://wordpress.org/support/users/digitalminds/)
 * (@digitalminds)
 * [17 years, 2 months ago](https://wordpress.org/support/topic/display-custom-fields-posts-on-static-page/)
 * I’m using the code below to display the titles of the last 8 posts on a static
   page:
 *  <?php
    # Here starts Mini Loop trick: You can use this code, but _at your own
   risk_ # If you want to improve this code, you’re welcome 😉 $how_many=8; //How
   many posts do you want to show ?> <ul id=”news”> <?php $news=$wpdb->get_results(“
   SELECT ID,post_title FROM $wpdb->posts WHERE `post_type`=\”post\” AND `post_status`
   = \”publish\” ORDER BY `post_date` DESC LIMIT $how_many”); foreach($news as $
   np){ printf (”
    - 
    - “, $np->ID,$np->post_title);
       } ?>
    - Now I want also to show the value of a custom field after the title, does 
      anyone know how to realize this?

Viewing 5 replies - 1 through 5 (of 5 total)

 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [17 years, 2 months ago](https://wordpress.org/support/topic/display-custom-fields-posts-on-static-page/#post-1016335)
 * You’ll want to use something like `get_post_custom` but review [Using_Custom_Fields](http://codex.wordpress.org/Using_Custom_Fields)
   for a discussion of the topic.
 * Also might direct you to other possible choices on presenting posts:
    [http://www.daobydesign.com/blog/2007/07/modifying-wordpress-front-page/](http://www.daobydesign.com/blog/2007/07/modifying-wordpress-front-page/)
   [http://weblogtoolscollection.com/archives/2008/04/13/define-your-own-wordpress-loop-using-wp_query/](http://weblogtoolscollection.com/archives/2008/04/13/define-your-own-wordpress-loop-using-wp_query/)
 *  Thread Starter [digitalminds](https://wordpress.org/support/users/digitalminds/)
 * (@digitalminds)
 * [17 years, 2 months ago](https://wordpress.org/support/topic/display-custom-fields-posts-on-static-page/#post-1016339)
 * Sorry Michael but I don’t see the connection between my problem and your links.
   I’ve already the titles of the posts now I also want to display the value of 
   a custom field but it doesn’t work with the examples mentioned in the codex using_custom_fields
 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [17 years, 2 months ago](https://wordpress.org/support/topic/display-custom-fields-posts-on-static-page/#post-1016346)
 * Please place the code you did use in a pastebin and report the link back here.
   Thanks.
 *  Thread Starter [digitalminds](https://wordpress.org/support/users/digitalminds/)
 * (@digitalminds)
 * [17 years, 2 months ago](https://wordpress.org/support/topic/display-custom-fields-posts-on-static-page/#post-1016382)
 *     ```
       <?php
         # Here starts Mini Loop trick: You can use this code, but _at your own risk_
         # If you want to improve this code, you're welcome ;)
         $how_many=8; //How many posts do you want to show
       ?>
       <ul id="news">
       <?php
         $news=$wpdb->get_results("SELECT ID,post_title FROM $wpdb->posts
           WHERE <code>post_type</code>=\"post\" AND <code>post_status</code>= \"publish\" ORDER BY <code>post_date</code> DESC LIMIT $how_many");
         foreach($news as $np){
           printf ("<li><a href=\"index.php?p=%s\">%s</a></li>", $np->ID,$np->post_title);
         }
       ?>
       ```
   
 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [17 years, 2 months ago](https://wordpress.org/support/topic/display-custom-fields-posts-on-static-page/#post-1016396)
 * > but it doesn’t work with the examples mentioned in the codex using_custom_fields
 * An example of the code you used, that didn’t work, please.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Display Custom Fields posts on static page’ is closed to new replies.

## Tags

 * [custom fields](https://wordpress.org/support/topic-tag/custom-fields/)

 * In: [Requests and Feedback](https://wordpress.org/support/forum/requests-and-feedback/)
 * 5 replies
 * 2 participants
 * Last reply from: [MichaelH](https://wordpress.org/support/users/michaelh/)
 * Last activity: [17 years, 2 months ago](https://wordpress.org/support/topic/display-custom-fields-posts-on-static-page/#post-1016396)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
