Plugin Directory

Get Custom Field Values

Template Tags

The plugin provides six optional template tags for use in your theme templates.

Functions

  • <?php function c2c_get_custom( $field, $before='', $after='', $none='', $between='', $before_last='' ) ?> Template tag for use inside "the loop" and applies to the currently listed post.

  • <?php function c2c_get_current_custom( $field, $before='', $after='', $none='', $between='', $before_last='' ) ?>
    Template tag for use on permalink (aka single) page templates for posts and pages.

  • <?php function c2c_get_post_custom( $post_id, $field, $before='', $after='', $none='', $between='', $before_last='' ) ?>
    Template tag for use when you know the ID of the post you're interested in.

  • <?php function c2c_get_random_custom( $field, $before='', $after='', $none='' ) ?> Template tag for use to retrieve a random custom field value.

  • <?php function c2c_get_random_post_custom( $post_id, $field, $limit=1, $before='', $after='', $none='', $between='', $before_last='' ) ?> Template tag for use to retrieve random custom field value(s) from a post when you know the ID of the post you're interested in.

  • <?php function c2c_get_recent_custom( $field, $before='', $after='', $none='', $between=', ', $before_last='', $limit=1, $unique=false, $order='DESC', $include_pages=true, $show_pass_post=false ) ?> Template tag for use outside "the loop" and applies for custom fields regardless of post.

Arguments

  • $post_id Required argument (only used in c2c_get_post_custom()). The ID of the post from which the custom field should be obtained.

  • $field Required argument. The custom field key of interest.

  • $before Optional argument. The text to display before all field value(s).

  • $after Optional argument. The text to display after all field value(s).

  • $none Optional argument. The text to display in place of the field value should no field value exists; if defined as '' and no field value exists, then nothing (including no $before and $after) gets displayed.

  • $between Optional argument. The text to display between multiple occurrences of the custom field; if defined as '', then only the first instance will be used.

  • $before_last Optional argument. The text to display between the next-to-last and last items listed when multiple occurrences of the custom field; $between MUST be set to something other than '' for this to take effect.

Arguments that only apply to c2c_get_recent_custom():

  • $limit Optional argument. The limit to the number of custom fields to retrieve. (also used by c2c_get_random_post_custom())

  • $unique Optional argument. Boolean ('true' or 'false') to indicate if each custom field value in the results should be unique.

  • $order Optional argument. Indicates if the results should be sorted in chronological order ('ASC') (the earliest custom field value listed first), or reverse chronological order ('DESC') (the most recent custom field value listed first).

  • $include_pages Optional argument. Boolean ('true' or 'false') to indicate if pages should be included when retrieving recent custom values; default is 'true'.

  • $show_pass_post Optional argument. Boolean ('true' or 'false') to indicate if password protected posts should be included when retrieving recent custom values; default is 'false'.

Examples

  • <?php echo c2c_get_custom('mymood'); ?> // with this simple invocation, you can echo the value of any metadata field

  • <?php echo c2c_get_custom('mymood', 'Today's moods: ', '', ', '); ?>

  • <?php echo c2c_get_recent_custom('mymood', 'Most recent mood: '); ?>

  • <?php echo c2c_get_custom('mymood', '(Current mood: ', ')', ''); ?>

  • <?php echo c2c_get_custom('mylisten', 'Listening to : ', '', 'No one at the moment.'); ?>

  • <?php echo c2c_get_custom('myread', 'I\'ve been reading ', ', if you must know.', 'nothing'); ?>

  • <?php echo c2c_get_custom('todays_link', '<a class="tlink" href="', '" >Today\'s Link</a>'); ?>

  • <?php echo c2c_get_current_custom('meta_description', '<meta name="description" content="', '" />' ); ?>

  • <?php echo c2c_get_post_custom($post->ID, 'Price: ', ' (non-refundable)'); ?>

  • <?php echo c2c_get_random_custom('featured_image', '<img src="/wp-content/images/', '" />'); ?>

  • <?php echo c2c_get_random_post_custom($post->ID, 'quote', 1, 'Quote: <em>', '</em>'); ?>

  • <?php echo c2c_get_custom('related_offsite_links', 'Here\'s a list of offsite links related to this post:<ol><li><a href="', '">Related</a></li></ol>', '', '">Related</a></li><li><a href="'); ?>

  • <?php echo c2c_get_custom('more_pictures', 'Pictures I\'ve taken today:<br /><div class="more_pictures"><img alt="[photo]" src="', '" /></div>', '', '" /> : <img alt="[photo]" src="'); ?>

  • Custom 'more...' link text, by replacing <?php the_content(); ?> in index.php with this: <?php the_content(c2c_get_custom('more', '<span class="morelink">', '</span>', '(more...)')); ?>

Download

FYI

Compatibility beta

Your Setup

Log in to vote.

The Consensus

No data
100,1,1

Average Rating

5 stars
4 stars
3 stars
2 stars
1 star
(11 ratings)