WordPress.org

Ready to get started?Download WordPress

Plugin Directory

Custom Fields Creator

WCK Custom Fields Creator - easily create custom meta boxes for WordPress. It supports normal custom fields and custom fields repeater groups.

How do I display my custom fields in the frontend?

Let's consider we have a meta box with the following arguments: - Meta name: books - Post Type: post And we also have two fields defined: - A text custom field with the Field Title: Book name - And another text custom field with the Field Title: Author name

You will notice that slugs will automatically be created for the two text fields. For 'Book name' the slug will be 'book-name' and for 'Author name' the slug will be 'author-name'

Let's see what the code for displaying the meta box values in single.php of your theme would be:

<?php $books = get_post_meta( $post->ID, 'books', true ); 
foreach( $books as $book){
    echo $book['book-name'] . '<br/>';
    echo $book['author-name'] . '<br/>';
}?>

So as you can see the Meta Name 'books' is used as the $key parameter of the function get_post_meta() and the slugs of the text fields are used as keys for the resulting array. Basically CFC stores the entries as custom fields in a multidimensional array. In our case the array would be:

<?php array( array( "book-name" => "The Hitchhiker's Guide To The Galaxy", "author-name" => "Douglas Adams" ),  array( "book-name" => "Ender's Game", "author-name" => "Orson Scott Card" ) );?>

This is true even for single entries.

Requires: 3.1 or higher
Compatible up to: 3.5.2
Last Updated: 2013-5-9
Downloads: 11,239

Ratings

4 stars
4.9 out of 5 stars

Support

Got something to say? Need help?

Compatibility

+
=
Not enough data

0 people say it works.
0 people say it's broken.

100,4,4 100,2,2
67,3,2
100,1,1
100,1,1