Custom Fields Creator

WCK Custom Fields Creator offers an UI for setting up custom meta boxes for your posts, pages or custom post types. Uses standard custom fields to store data.

Custom Fields Creator Features:

  • Custom fields types: wysiwyg editor, upload, text, textarea, select, checkbox, radio
  • Support for Repeater Custom Fields and Repeater Groups.
  • Drag and Drop to sort the Repeater Fields.
  • Support for all input fields: text, textarea, select, checkbox, radio.
  • Image / File upload supported via the WordPress Media Uploader.
  • Possibility to target only certain page-templates, target certain custom post types and even unique ID’s.
  • All data handling is done with ajax
  • Data is saved as postmeta

Frontend WCK Custom Fields Creator usage example:

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 field with the Field Title: Book name
– And another text 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:

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

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

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.

Displaying images in frontend

In version 1.0.2 we changed the upload field from storing the url to the file into storing the attachment ID for the file.

So now you can use functions like wp_get_attachment_image, wp_get_attachment_image_src or wp_get_attachment_url depending on the desired functionality.

Now for a usage example:
Let’s consider we already have the contents of the image meta in a variable $image. This variable could contain the ID of the attachment or, if it was added before updating to CFC 1.0.2, the actual src of the file.

<?php
if( !empty( $image ) ){
  if( is_numeric( $image ) ){
     //this means we have an id stored.
     $attachment_image = wp_get_attachment_image_src( $image, 'full' );
     $src = $attachment_image[0];
  }
  else{
     /* we have the actual src stored */
     $src = $image;
  }
}
 
if( !empty( $src ) )
  echo '<img src="'.$src.'"/>';
?>