=== Get Custom Field Values === Contributors: coffee2code Donate link: http://coffee2code.com/donate Tags: custom fields, widget, widgets, shortcode, meta, extra, data, post, posts, page, pages, coffee2code Requires at least: 2.8 Tested up to: 3.0.1 Stable tag: 3.2 Version: 3.2 Use widgets, shortcodes, and/or template tags to easily retrieve and display custom field values for posts or pages. == Description == Use widgets, shortcodes, and/or template tags to easily retrieve and display custom field values for posts or pages. The power of custom fields gives this plugin the potential to be dozens of plugins all rolled into one. This plugin allows you to harness the power of custom fields/meta data. Use the "Get Custom Field" widget, the `[custom_field]` shortcode (which has a sidebar widget to help you build the shortcode), or one of six template tags to retrieve and display custom fields. Find a custom field for the current post, a specified post, a recent post, or randomly. And for the custom field values found by the plugin, you may optionally specify text or HTML to appear before and after the results. If nothing is found, then nothing is display (unless you define text to appear when no results are found). If multiple results are found, only the first will be displayed unless you specify a string to be used to join the results together (such as ","), in which case all will be returned. Visit the Examples section to see how this plugin can be cast in dozens of different ways. There are six template tags provided by this plugin. Here they are, with an explanation of when they are appropriate for use: * `c2c_get_custom()` : Use this inside "the loop" to retrieve a custom field value for a post * `c2c_get_current_custom()` : This is only available on the permalink post template (single.php) and page template (page.php). Can be used inside or outside "the loop". Useful for using custom field to define text you want to include on a post or page's header, footer, or sidebar. * `c2c_get_post_custom()` : Useful when you know the ID of the post whose custom field value you want. * `c2c_get_random_custom()` : Retrieve the value of a random instance of the specified custom field key, as long as the field is associated with a published posted, non-passworded post (you can modify a setting in the plugin file to search passworded posts as well). * `c2c_get_random_post_custom()` : Retrieves the value of random custom field(s) from a post when you know the ID of the post you're interested in. * `c2c_get_recent_custom()` : Retrieves the most recent (according to the associated post's publish date) value of the specified custom field. You can filter the custom field values that the plugin would display. Add filters for '`the_meta`' to filter custom field data (see the end of the code file for commented out samples you may wish to include). You can also add per-meta filters by hooking '`the_meta_$sanitized_field`'. `$sanitized_field` is a clean version of the value of `$field` where everything but alphanumeric and underscore characters have been removed. So to filter the value of the "Related Posts" custom field, you would need to add a filter for '`the_meta_RelatedPosts`'. == Installation == 1. Unzip `get-custom.zip` inside the `/wp-content/plugins/` directory, or upload `get-custom.php` to `/wp-content/plugins/` 1. (optional) Add filters for 'the_meta' to filter custom field data (see the end of the plugin file for commented out samples you may wish to include). And/or add per-meta filters by hooking 'the_meta_$field' 1. Activate the plugin through the 'Plugins' admin menu in WordPress 1. Give post(s) a custom field with a value. 1. (optional) Go to the Appearance -> Widgets admin page to create one or more 'Get Custom Field' sidebar widgets for your widget-enabled theme. 1. (optional) Use one of the six template functions provided by this plugin to retrieve the contents of custom fields. You must 'echo' the result if you wish to display the value on your site. == Template Tags == The plugin provides six optional template tags for use in your theme templates. = Functions = * `` Template tag for use inside "the loop" and applies to the currently listed post. * `` Template tag for use on permalink (aka single) page templates for posts and pages. * `` Template tag for use when you know the ID of the post you're interested in. * `` Template tag for use to retrieve a random custom field value. * `` 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. * `` 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 the custom field value(s), if any are present (defaults to ''). * `$after` Optional argument. The text to display after all the custom field value(s), if any are present (defaults to '') * `$none` Optional argument. The text to display in place of the field value should no field values exist; 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 = * ` // with this simple invocation, you can echo the value of any metadata field` * `` * `` * `` * `` * `` * `Today\'s Link'); ?>` * `' ); ?>` * `ID, 'Price: ', ' (non-refundable)'); ?>` * `'); ?>` * `ID, 'quote', 1, 'Quote: ', ''); ?>` * `