coffee2code.com/wp-plugins/get-custom-field-values
Easily retrieve and control the display of any custom field values/meta data for posts, inside or outside “the loop”. The power of custom fields gives this plugin the potential to be dozens of plugins all rolled into one.
This is a simple plugin that allows you to harness the power of custom fields/meta data. You can define $before and/or $after text/HTML to bookend your results. If no matching custom field by the name defined in $field was found, nothing gets displayed (including no $before and $after) (unless $none is defined, in which case the $none text gets used as if it was the match). If multiple same-named custom fields for a post are defined,only the first will be retrieved unless $between is defined, in which case all are returned, with the $between text/HTML joining them). If $before_last is defined along with $between, then the text/HTML in $before_last is used prior to the last item in the list (i.e. if you want to add an “and” before the last item). Head down to the Tip & Examples section to see how this plugin can be cast in dozens of different ways.
- Download the file get-custom.zip and unzip it into your wp-content/plugins/ directory.
-OR-
Copy and paste the the code ( get-custom.phps ) into a file called get-custom.php, and put that file into your wp-content/plugins/ directory. - Optional: Add filters for ‘the_meta’ to filter custom field data (see the end of the file for commented out samples you may wish to include) *NEW*: Add per-meta filters by hooking ‘the_meta_$field’
- Activate the plugin from your WordPress admin ‘Plugins’ page.
- Give a post a custom field with a value.
- Use the function c2c_get_custom somewhere inside “the loop” and/or use the function c2c_get_recent_custom outside “the loop”; use ‘echo’ to display the contents of the custom field; or use as an argument to another function
function c2c_get_custom ($field, $before='', $after='', $none='', $between='', $before_last='')
- $field : This is the name of the custom field you wish to display
- $before : The text/HTML to display before all field value(s)
- $after : The text/HTML to display after all field value(s)
- $none : The text/HTML 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 : The text/HTML to display between multiple occurrences of the custom field; if defined as ”, then only the first instance will be used
- $before_last : 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
function c2c_get_recent_custom ($field, $before='', $after='', $none='', $between='', $before_last=', ', $limit=1, $unique=false, $order='DESC', $include_static=true, $show_pass_post=false)
- $field : This is the name of the custom field you wish to display
- $before : The text/HTML to display before all field value(s)
- $after : The text/HTML to display after all field value(s)
- $none : The text/HTML 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 : The text/HTML to display between multiple occurrences of the custom field; if defined as ”, then only the first instance will be used
- $before_last : 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
- $limit : The number of recent custom field values you want returned; default is 1
- $unique : Boolean value (either ‘true’ or ‘false’) to indicate if only the latest instance of $field should be considered, and subsequent occurances of $field would be skipped in the search; default is ‘false’
- $order : The order the results should be returned, either ascending/increasing (‘ASC’) or descending/decreasing (‘DESC’); default is ‘DESC’
- $include_static : Boolean (‘true’ or ‘false’) to indicate if static posts (i.e. “pages) should be included when retrieving recent custom values; default is ‘true’
- $show_pass_post : Boolean value (either ‘true’ or ‘false’) to indicate if passworded posts should be considered in the search; default is ‘false’
Do you simply want to retrieve the value of a custom field/meta data?
<?php echo c2c_get_custom('mood'); ?>
Want a moods plugin?
<?php echo c2c_get_custom('mood', '(Current mood : ', ')'); ?>
Example results:
[if ‘mood’ is set to ‘happy!’] (Current mood: happy!)
(add filters if you wish to use smilies, etc)
Want a currently reading/currently listening to plugin?
<?php echo c2c_get_custom('reading', 'Currently reading :'); ?>
[if value for ‘reading’ is ‘Cujo’] Currently reading: Cujo
<?php echo c2c_get_custom('reading', 'Currently reading: <i>', '</i>', '', '</i>, <i>'); ?>
[if three ‘reading’ fields were defined, with values ‘Carrie’, ‘Cujo’, and ‘The Shining’]
Currently reading: Carrie, Cujo, The Shining
<?php echo c2c_get_custom('listening', 'Now playing ', ' on my stereo.', 'nothing'); ?>
[if value for ‘listening’ is ‘The Beatles’] Now playing The Beatles on my stereo.
[if no value defined for ‘listening’] Now playing nothing on my stereo.
Want a Post Icon plugin (image to display for the post, not derived from category)?
<?php echo c2c_get_custom('post_icon', '<img alt="post icon" class="posticon" src="/wp-images/posticons/', '.gif" />', 'blank'); ?>
[if value for ‘post_icon’ is ‘wordpress’]
<img alt=”post icon” class=”posticon” src=”/wp-images/posticons/wordpress.gif” />
Want to do per-post customized ‘more’ text? (to override the default “(more…)”) (This example will show the default “(more…)”, which you can of course change, if you don’t define the custom field ‘more’ for a post)
In index.php, look for this function: <?php the_content(); ?>
Replace it with this:
<?php the_content(c2c_get_custom('more', '<span class="more">', '</span>', '(more...)')); ?>
- WordPress Support Forums announcement of Get Custom Field Values
- 26 Mar 2005 : v2.1 released —
- Removed the $filter argument from c2c_get_custom() and c2c_get_recent_custom()
- Replaced $filter argument with more robust filtering approach: filter every custom field via the action ‘the_meta’, filter specific custom fields via ‘the_meta_$field’
- Add argument $include_static (defaulted to true) to c2c_get_recent_custom(); static posts (i.e. “pages”) can be optionally excluded from consideration
- Verified to work for WP 1.5 (and should still work for WP 1.2)
- 08 Sep 2004 : v2.01 and v.202 release — minor bugfixes
- 07 Sep 2004 : v2.0 released :
- Added the new function
c2c_get_recent_custom()
that allows retrieving custom/meta data from outside “the loop” - Better filtering (on meta field itself instead of final output string)
- Per-call filtering of meta fields
- Prepended all functions with “c2c_” to avoid potential function name collision with other plugins or future core functions… NOTE: If you are upgrading from an earlier version of the plugin, you’ll need to change your calls from
get_custom()
toc2c_get_custom()
- Changes to make the plugin WordPress v1.3 ready (as-yet unverified)
- Switched to MIT license
- Added the new function
- 22 Jul 2004 : v1.0 released — added argument of $before_last (which, went $between is also defined, will be used to join the next-to-last and last items in a list); added invocation of an action called ‘the_meta’ so that you can do add_filter(‘the_meta’, ‘some_function’) and get custom field values filtered as they are retrieved; to faciliate use of this plugin as the argument to another function, this plugin no longer echoes the value(s) it retrieves (user must prepend ‘echo’ to the call to get_cust())
- 30 Jun 2004: v0.91 bugfix release
- 30 Jun 2004: v0.9 released to the public
Copyright (c) 2004-2005 by Scott Reilly (aka coffee2code)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
252 replies on “Plugin: Get Custom Field Values”
Love get custom fields plugin. has done wonders for my site, but I am running into issues trying to embed it into an tag.
It doesnt retrieve the value when embedded inside an container in the tag. Example below:
Any suggestions on making this work would be wonderful. Thank you.
Disregard my last post. It looks to be working now!
Hi Scott
I am using two of your plugins on bond.write2kill.com/. Both are a big help.
But I wish this one could be combined in some wy with Customizable Post Listings. That would be a bomb!
Anyway, thanks for creating these plugins. Your credits are here: bond.write2kill.com/?page_id=1511
Cheers.
w2k
[…] ?????Wordpress???????“????????????”????Wordpress???????????????????Wordpress??????“Custom Fields”?????????Scott Reilly?“Get Custom”?????????????? […]
Thanks again
I’d wanted to add a “via” attribute to the Dailies over there on the left, and the custom field in the post form is the perfect place for that. But I wasn’t quite sure how to alter the output of the the_meta(); tag. Fortunately, Scott Reilly at code2coffee has already written a plug-in to handle it. Yay!
Thanks Scott.
I have tried using the Adhesive plugin which appears to be the ideal option for what I am trying to do, but for some reason it just does’nt want to work on my setup.
I will keep an eye out for any new options you may find
Thanks Scott.
I have tried using the Adhesive plugin which appears to be the ideal option for what I am trying to do, but for some reason it just does’nt want to work on my setup.
Disregard my last post. It looks to be working now!
Hi,
I am contacting you for your valuable feedback on our new WordPress powered site redesign and that we have used some of your pluggins/themes (though all are customized heavily to suit our needs). Please visit, review and provide your valuable feedback, criticism, and suggestions on our corporate site preview (I am sorry that the site contains dummy content for now – but on launch will contain actual content)
Dollars 5 Complete ( www.dollars5.com/plete ) and Dollars 5 Compile labs ( www.dollars5.com/pile ) – these sites are heavily modified to suit our new Corporate identity and re-branding as a Mobile Applications Developer.
Thanks for your efforts on WP and your contributions through pluggins/themes.
You can also leave your crtics at wordpress.org/support/topic/99820
Regards.
—
Sita
India
[…] ?????Wordpress???????“????????????”????Wordpress???????????????????Wordpress??????“Custom Fields”?????????Scott Reilly?“Get Custom”?????????????? […]
[…] ?????Wordpress???????“????????????”????Wordpress???????????????????Wordpress??????“Custom Fields”?????????Scott Reilly?“Get Custom”?????????????? […]
coool but how will I publish it ?
It is an awesome plugin dude ..thanx 🙂
Fantastic plugin! It seems like it should be easy to use basic php and WordPress functions to simply display the contents of a custom field, but it wasn’t so easy after all. Your plugin worked perfectly right off the bat. Thanks!
Great Plugin. As I’m not very experienced with WP I’d need somebody’s help. One example above says:
That’s exactly what I would like to do. I’ve got a custom field “type”. If the value for “type” is “concert”, an img called concert.gif should be shown, if the value is “cd” an img called cd.gif should be shown.Thanks
mediaman
Fantastic plugin.
I think your plugins are all great — though it is a little troubling to see that the last updates for most of them are circa 2005, being now that it is 2007. I’m wondering if there are any modern versions of these plugins around? Stay cool.
Always, your friend in finance,
1mil from millionster.com
[…] ?????Wordpress???????“????????????”????Wordpress???????????????????Wordpress??????“Custom Fields”?????????Scott Reilly?“Get Custom”?????????????? […]
Thanks again
[…] ?????Wordpress???????“????????????”????Wordpress???????????????????Wordpress??????“Custom Fields”?????????Scott Reilly?“Get Custom”?????????????? […]
$order=’DESC’, Replace as ASC Working Thanx 😉
I would use this plugin by indicating “post_id”, but it would not be supported as the option, I think.
Does anybody know such usages?
I’m hoping this will do what I would like. Having a problme with installing on wp2.1. I’m getting an error. Is there any way to get help?
Thanks
I want to use one particular custom field as a link. How do I use this plugin to make a clickable link?
See this page where a non-clickable link appears:
www.newswatch.in/newspaedia/?p=181
See this page where there is no relevant link:
www.newswatch.in/newspaedia/?p=144
Creating a simple clickable link is fine when the href element is the funciton of this plugin. So just “Official link” itself can be clickable. But when there is no link, it will sitll appear and be a non-clickable.
Creating a simple clickable link is fine when the href element is the funciton of this plugin. So just “Official link” itself can be clickable. But when there is no link, it will sitll appear and be a non-clickable.
Enjoyed browsing through the site. Keep up the good work. Thanks and Greetings
[…] www.coffee2code.com/archives/2004/06/30/plugin-get-custom/ […]
[…] Get Custom?wordpress??????????????blog????????????slashdot?????????Get Custom?????????????????????????????????????????????????Markdown?wordpress????????????????????????HTML???????Markdown???????? […]
Hey there; we’re trying to use your pluggie to employ a link switch like so: if a target-URL is given in Custom Field “target” then make the post title link there. Else make it link to article’s permalink. To attain this we tried:
and
and
With the last one we get the permalink to show if no target is given. However, IF one is given, the target URL is issued attached to the permalink URL. Any ideas what we’re doing wrong here? Thank you in advance!
oh dear! the code was of course stripped out; silly me. Sorry! These are the three lines again:
<?php echo c2c_get_custom('target', '', '', ' . the_permalink() . '); ?>
and<?php echo c2c_get_custom('target', '', '', . the_permalink() . ); ?>
and<?php echo c2c_get_custom('target', '', '', the_permalink() ); ?>
[…] www.coffee2code.com/archives/2004/06/30/plugin-get-custom/ […]
Any chance that you know of a work around for Jamie’s problem up in commet #137?
I’m trying to do the same thing. Is it possible to set this up to grab get_recent_custom on a per post basis?
Thanx
Great Plugin
[…] been playing around with the Get_custom plugin to see if I could get it to work a litle better than I did the first time I glanced at it, and […]
[…] was all right for a while. After a little tweaking to my theme, and reinstalling and activating the Get_Custom plugin, (which, by the way, is another one that is highly recommended because of its extreme flexibility […]
[…] way inclined” (nerd alert): The code relies on two other plugins: Coffee2Code’s Get Custom Field Values and no sq’s RunPHP. The itinerary page includes the php script which calls for the custom […]
any word on why the $order variable doesn’t seem to work with the c2c_get_custom() r c2c_get_recent() functions?
I’ve asked previously and on the forums but no response… there’s no logic whatsoever to how it orders the custom fields.
I’d really appreciate knowing how to make it work, thanks
um, are you blocking syncbox AT gmail DOT com because I ask too many questions? I noticed that all my posts asking about $order were “being held for moderation” but I could post using a different email address.
$order doesn’t work. It doesn’t provide any order… I’ve tested it in both functions and put numbers in the fields to verify that it doesn’t work either DESC or ASC and certainly doesn’t display the fields in the order they were entered.
Could you please acknowledge that or suggest a fix or something?
TIA
wp version 2.2 and 2.2.1 btw.
[…] Get Custom Fields plugin is an extremely versatile WordPress Plugin. It’s really like having dozens and dozens […]
[…]   ç»å¸¸æœ‰Wordpressçš„æ–°ç”¨æˆ·é—®æˆ‘ï¼Œâ€œæ€Žä¹ˆå¾€æ–‡ç« ä¸æ’入附件呢?â€ï¼Œé»˜è®¤çš„Wordpressä¸æä¾›è¿™æ ·çš„åŠŸèƒ½ï¼Œä½†æ˜¯å®ƒæ供了方法。在Wordpressä¸ä½ å¯ä»¥ä½¿ç”¨â€œCustom Fieldsâ€æ¥è´´ä¸Šè‡ªå®šä¹‰æ•°æ®ï¼ŒScott Reilly的“Get Customâ€æ’件å¯ä»¥å¾ˆå®¹æ˜“地åšåˆ°è¿™ä¸€ç‚¹ã€‚ […]
[…] posted before about the excellent and versatile Get Custom Field Values WordPress Plugin [1]. It is a wonderfully useful plugin that can do many different things throughout your blog. It’s […]
[…] process involved to make this work utilizes the Get Custom Field Values plugin[4]. For each post you write you will enter a custom title and a custom description for each tag and […]
[…] “Plugin: Get Custom Field Values” by Coffee2Code (not new, but classic) […]
[…] Completely customisable, exploitable, and potentially extremely useful. Be creative, go get the coffee2code custom field value plugin! Easily retrieve and control the display of any custom field values/meta data for posts, inside or […]
[…] Get Custom Field Values: WP plugin, which takes advantage of WordPress’ custom fields by letting you control their placement and appearance. I used this for non-category pages to create custom headers such as résumé, about, contact, and all the error and search pages. […]
[…] coffee2code.com » Blog Archive » Plugin: Get Custom Field Values This is a simple plugin that allows you to harness the power of custom fields/meta data. You can define $before and/or $after text/HTML to bookend your results. If no matching custom field by the name defined in $field was found, nothing gets displayed (i (tags: plugin wordpress metadata) […]
[…] Get Custom Field Values: WordPress Loop’u içinde veya dışıda, yazıya ait özel alan deÄŸerlerini (Custom Field) kolayca görüntülemek için bu eklenti çok faydalı. WordPress 2.1.2 ile uyumlu. Yazı içerisinde özel alanları göstermek için ise Enzymes eklentisi kullanılabilir ama WP 2.1 ile uyumlu mu emin deÄŸilim. […]
[…] The link to the plugin is: Coffee2code.com […]