Plugin: Get Custom Field Values
http://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.

I’m getting the collowing error:
I’ve found the source of the problem mentioned above, just add four lines of code. I’ll submit it as a bug fix, or you can see my post on it here.
Thanks for reporting the bug, Vincent! And thanks for suggesting a bugfix, guard. I had written a fix that did essentially what yours did, though slightly different, but I’m glad to be able to compare to yours to know that the fix should work. The plugin files have been updated to v0.91 as a result.
Hi Scott, and thanks for the very useful plugin, it’s an important part of a site I’m currently working on. I made some changes to the code, so it also allows Textile and includes a string before the last item in a list (like an “and”). Drop me an e-mail and I’ll send them your way.
Hi, Luís; small world. As it so happens the next release of this plugin will address the two situations for which you made code changes. Not sure about an ETA for the release, but it should be within the next few days. Are you converting your personal blog, or perhaps FM?
Plugin Updated to v1.0
A few new features and changes have been made to this plugin. Users of previous versions of this plugin should take note of the changes:
1. This plugin no longer automatically echoes the result. Instead, it returns the value it would’ve echoed. (See the examples above for the use of ‘echo’.) Why? So that this plugin could gain more versatility by being able to be used as an argument to other functions. For instance, you want customized “more” link text? Change this line in your index.php:
<?php the_content(); ?>
to:
<?php the_content(get_custom('more', '<span class="more">', '</span>', '(more...)')); ?>
If you then define text for the ‘more’ custom field and use the <!–more–> feature of WP, your text will be used for the link. Otherwise, the default “(more…)” will be used. Also, you’ll be able to customize the appearance of the “more” link (thanks to the <span>).
2. Now you can filter your custom field values/meta data via the add_filter() function. The name to filter is ‘the_meta’. The end of the plugin file contains some commented-out examples of filters you could add.
3. An additional argument, $before_last, has been added. If defined ($between must also be defined), then the $before_last value will be used to go between the next-to-last and last items in a list. That way you can now get something like “, B, C, D, and E”
Observations
More Wordpress plugin goodness, web toys, forgiveness, and games.
<span class="more"> </span>How could I use this outside the loop and get it to only show the last x days?
I’m actually working on this right now. Check back again after a few days.
Hello Scott,
I have just installed your get custom plugin and I am hoping I can use it to do the following:
I would like to make a sticky of one post in each category within my site - i.e. one post that will remain at the top of the page in any given category.
Is this possible using your get custom plugin? Please, please tell me it is - and if so - how do I go about making it happen?
Hoping to hear from you soon:)
Thank you
Well, presently, it doesn’t seem easily achievable using the plugin. However, I am working on modifications to the plugin that *may* faciliate such a thing. Keep an eye out here or at the WP support forums for when I update this plugin.
There are a variety of ’sticky’ post plugins already available that are specifically geared toward that task… (but I’ll still contemplate using custom fields for it).
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 again
Any way to edit this plugin so I can edit it through css. Color, Fonts, things like that. Thank. By the way, this is a very useful plugin
The plugin itself won’t add any data that isn’t already defined in the custom field values it obtains or that were specified in its arguments.
If you say what you’re trying to accomplish, I could direct you better, but the solution likely involves defining CSS-targetable elements when you send the arguments to get_custom().. Such as:
That way you could style this via
b.moodor.mood.If you just want the custom value part styled, you could do:
This is a fab plugin & has made it easy for me to do many cool things. Thanx
Hi, I download and installed this pluin just as i have installed others. But once I open any page in the browser, the entire coding of the get-custom.php shows up. What could have been wrong?
How exactly did you obtain the plugin file: via the zip file or by saving the .phps file into a .php file? I would need more information about the steps you have taken; I don’t know offhand what the issue might be.
Works great for me
Easy to customize as well.
Hi, I’ve tried your plugin in WP 1.3 (alpha 3) and WP 1.2, but I can’t get it to work:
I’m using this piece of code:
<?php echo c2c_get_custom('publicado'); ?>The plugin is activated and the custom field is exactly “publicado”
What I’m doing wrong?
Thanks in advance
poper: Try reobtaining the plugin, now version 2.01. There was a bug with it that I hope solves things for you.
Hi, thanks for yor quick answer. I’ve installed the new version on WP 1.3 alpha 3 and it shows the meta without problems, But if a post doesn’t use meta, I get this error:
Warning: array_slice(): The first argument should be an array in c:\desarrollo\appserv\www\wordpress\wp-content\plugins\get-custom.php on line 135
I use this code:
I’ve included the third parameter (” for $none) in order to show nothing when no meta are set, but it doesn’t work.
Another question: is it possible to hide an existing meta, I mean, I want to hide some meta in certain posts (a sticky one, using Adhesive plugin, that creates a custom field called ’sticky’). I’ve think about using CSS. is it right?
Thanks again for your great work
poper: Sorry about that. I was manually copying code changes from a test copy to the official copy and neglected two things that necessitated these two bugfix releases. v2.02 is available now, which should solve that problem. You don’t need to explicitly specify the
$nonesince it defaults to not showing a meta if that particular one isn’t defined.I’m not sure what you are asking about for your second question, about hiding an existing meta. Meta data is only shown if you explicitly make a call to show it (i.e. via
c2c_get_custom()). Otherwise, the meta data isn’t shown. Unless you mean that you have defined a meta field that you want shown for all posts EXCEPT for certain posts (i.e. a sticky post), even if the sticky post has the meta field. Is that it?It works like a charm! (both, in WP1.2 & WP1.3)
About the second question, forget about that, I was a bit confused, but your last comment has helped me a lot.
Thanks you!
Glad to hear you’re up and running with it. Thank you for the feedback!
[…] bilibalado @ 10:23 am ???????????coffe2code??????Get_custom??????????????????????? […]
Wonderful. This works great! More great work, Scott!
Why isn’t this built in to WP???
Hi, nice plugin.
I do have a question though. c2c_get_recent_custom seems to work such that it will get $field from the latest post that has it defined, even if it is not the most recent post in wordpress. For something I’m trying to implement I want it to only get the $field from the most recent post if it is defined, otherwise use $none. Any idea about how I could hack your script (namely the query) to make this the case?
[…] ing a new plugin, even before I bother to fix the things I already mentioned needed work. Get Custom Field Values is the name of the plugin, and that’s what it doe […]
I’m currently working on running my fiction archive with WP and discovered your plugin. Thanks so much for making it! It’s perfect for adding values like ‘pairing’ or ‘fandom’ and worked like a charm - until today. When I went to add some new posts to http://fanfiction.thebookshelf.org/archives/category/lotrips/ I added a custom field, as usual - only today it simply doesn’t show up. It says ‘Custom field added’ but nothing changes, although it stills shows just fine on the older posts. Any idea why that could be?
Ruby: Thanks!
Naim: Good suggestion. I’ll see if I can figure out a good way to incorporate your request into a future version of the plugin.
Shirasade: Are you still having the problem? Offhand, I’m not sure what could be wrong, though admittedly I’m not fully clear on the nature of the problem. Do you assign the post an existing custom field key, or did you create a new one? Was there anything different about the custom field value text that you used? If you go back and edit the post, is the custom field still there (and therefore saved with the post and still exists).
Great, I look forward to it. Thanks for listening to my idea.
This plugin is awesome! I love it, thank you
Hi Scott,
I am trying to use your plugin to add custom keywords to a post when displayed in single mode. This would require that it works outside the loop, and that it only returns something when there is a custom field (ie “keyword”) for the post which is displayed.
How could I use c2c_get_recent_custom to do this?
Thanks
[Sorry for this spam-ish comment: I am currently contacting a few WP plugin developers with this message… but couldn’t find a direct email to send you that… feel free to delete this comment afterward]
I just released version 1.0 of what should soon enough become the somewhat official WP Plugin repository (currently figuring out the domain name and how it will be presented from the main wordpress site).
The page is already flooded by users, but unfortunately still rather low on registered plugins (well, considering there are thousands of WP plugins floating around on the net).
So I have been making a round-up of everybody’s favorite plugins and I am currently working on getting these in, so as to get the DB off to a good start. Yours being one of them
You can have a look at the current DB here:
http://www.unknowngenius.com/wp-plugins
Ideally, it would be awesome if you could register it yourself, as it would both make life easier for me and give you greater control on how your plugin is presented (and easy access to admin options, for example if you want to notify users of an upgrade)… It is a really painless and quick process, probably less than 3 minutes (maybe 5, if you want to make it one-click installable):
http://www.unknowngenius.com/wp-plugins/faq.html#dev
However, if you do not feel like taking the time to do that now, I would actually like to go ahead and add it myself, so that users can have access to it in the meantime… Of course you’ll be free to regain control of its entry in the DB at any moment (simply would have to create an account and contact me to transfer its ownership). Before doing that, though, I first wanted to know if it was alright with you (and incidentally if couldn’t do it yourself
…
In addition, I am currently working on v.2.0 whose top feature would be greater install options for developers (I’m really shooting for the 90% one-click instability)… I would love to hear from you what type of extra-install steps your plugin require (SQL, file perms etc)…
Sorry for the length and please do not hesitate to contact me directly if you got any question/suggestion/comment…
Cheers
Is it possible to use this plugin as a ‘filter’ in order to display only entries that meet a certain criterion for the value of a custom field. If so, how would I go about doing this?
[…] teresting trip: I’ve gotten to know PHP a lot better, I’ve found the Get Custom Field Values plugin for WordPress and am having a great de […]
[…] teresting trip: I’ve gotten to know PHP a lot better, I’ve found the Get Custom Field Values plugin for WordPress and am having a great deal of fun w […]
How would I use this to display a list of all the custom field data for every post? I’m using a custom field fLink for links to files and I want to make a page that lists all the links. Is this doable?
Holy Shmoly,
This would have to be one of the best keep secrets!.
Bloody handy plugin this one. I was looking for something to get my keywords inserted and I found this..WOW is about all I can say (and I’ve only used to call the meta so far and theres so much more)
Thanks a million for this one Scott
dang..
I broke things in the site template again.
——–
Got it fixed.
[…] isplayed in my posts is discrete data saved in the MySQL database and pulled out using the Get Custom Field Values. I started posting meta data on Nov 1st and I need to […]
Hello there,
Found your plug in and love the possibilities of what it can do. ^^ I installed it on my plugin folder, activated the plug-in and the custom field comes out, but now it doesn’t seem to be showing up on my page. I’m not entirely sure what I’m lacking.
1. unzipped and uploaded the plugin (get_custom.php)
2. activated the plugin
3. added the code < ?php echo c2c_get_custom('mood', '(Current mood : ', ')'); ?> to the main index.php where I want it to show
4. made the custom field: set the key to “mood” and value to “happy” via editing my latest post, and then saving everything
Is there any step that I’m missing?
Oh, and get_custom.php is actually get-custom.php Stupid typos.
Talk about titilizing plugin!
, which is what I’m trying to do.It seems like the perfect plugin for the purpose of writing a unique
I created a “static” page (I’m running WP 1.5 alpha 6) called “about”.
I’ve added a custom field, via the admin tool, called “thispage”
with the value “about”. In the header template, I write
The plugin is activated in the admin tool, the custom value is added and visible even through successive edits of the page.
Please help!
ummmm… seems like the pertinent code excerpt got lost.
I was trying to write:
<body id="<?php echo c2c_get_custom('thispage'); ?>">In order to get a unique
body id.But I only get a:
<body id="">Uhm, bad ass plugin you got here. I couldn’t believe my eyes. I was going to get my PHP programmer to help us mod this up and bam! Already done.
I got one issue to ask though in the implementation of it.
On the home page of my blog, I want to keep a short and sweet summary of the posts, with a “read here for more” link underneath.
So under the proverbial:
<?php the_content(); ?>I entered a few
<?php echo c2c_get_custom('Cool fea... etc.The thing is, enter tool, truncates the body of the content, but doesn’t do the c2c’s stuff very well. It displays it in the homepage regardless, defeating the purpose that I’m trying to get.
I’ve only just started getting familiarizing myself with WP a month ago, so pardon in advance, if it’s something dumb and obvious.
Kind regards!
B.A.R.
http://www.badassreviews.com
Rob: Offhand I don’t believe the plugin currently allows what you are looking for.
c2c_get_recent_custom(), as you know, works outside the loop, but in so doing it isn’t associated with any particular post. It gets the recent occurances of custom fields. There are other plugins geared toward your request. The WordPress Wiki has two (at the moment) if you search that page for the term “keyword”.Joey Horne: Depends on how you wish to retrieve posts via their custom fields. If you are looking to modify your main page to show and/or skip posts based on the presence/value of a custom field, that is one thing; if you are looking to pull a list of posts based on custom field value (i.e. for use in a sidebar or some such), that is another. The latter is a feature forthcoming in a later release of this plugin. The former is something that requires you to make some changes to index.php, for which I’d need more info from you to determine what you want done.
Joe: Using the plugin function
c2c_get_recent_custom()you can retrieve all custom fields of a given name from all posts. Currently the fields are presented in reverse chronological order (an option allows you to change that so they are presented in chronological order) based on the date of the post that each custom field was associated with.Rin: Did you echo the result of the function in index.php, like so:
<?php echo c2c_get_custom('mood'); ?>Without the ‘echo’ nothing will appear on the page. (Earlier releases of this plugin did not require the ‘echo’…)
mquick:
c2c_get_custom()only functions within “the loop”; the HTML<body>tag takes place prior to the loop. What you want is doable though. If you’re still interested, I can help you with it.B.A.R.: I think I catch the gist of what you’re saying. You basically don’t want the custom field stuff to appear on the main page, correct? Assuming that is the case (and always the case), you could wrap the c2c_get_custom calls so they only appear when the post is viewed by itself. Something like this:
Perfect!
Thank you Scott.
I got another issue that has come up that’s a little perplexing.
When I got to edit an article that’s already been published, (say I forgot a custom field), it doesn’t work. I click on a Add Custom Field and it simply redraws the screen and wipes out what I wrote for it.
Anyone else experience this?
As it stands, I can only add custom fields to new posts that haven’t been published yet. Is this behaviour normal or did I mess up something unique to me?
Thanks again Scott for your answer. I’m going to give that a shot!
Regards,
B.A.R.
http://www.badassreviews.com
Using this plugin for a local install of WP-as-archive and quickly becoming its biggest fan. It seriously rocks.
Just a question, would it be possible to have two functions for the same custom field, but with two different ‘before’ and ‘after’ variables? I.e. -
I might need that for another plugin at some point. Thanks!
Method of handling replies
Because (slight) interest has been expressed in the way I display replies to comments, and (slight) interest has been expressed in the method I used to set it up, I figured I should post the steps I took to make it how it is. All the code used here was…
B.A.R.: Have you tried adding the new custom field and then clicking “Save” or “Save and Continue Editing” for the post instead of the “Add Custom Field” button? That might work for you.
Andrea: I’m not sure exactly what you’re asking… do you mean somehow change the ‘before’ and ‘after’ text depending on something else? If so, yes. For instance, in index.php (if you are running 1.2.x) you could do something like:
That would use ‘before1′ and ‘after1′ on the permalink page, and ‘before2′ and ‘after2′ on all other pages (the index, archives, etc).
Unless you really just meant using ’some_field_key’ multiple times, via numerous calls get c2c_get_custom(), but with different before/after text. If so, that is valid also.
If I’ve failed to answer your question feel free to try me again.
Oops, sorry for not being more specific. I meant the latter (although I’m curious to see the code you provided, it’s invisible in your comment), and an example–although not what I had in mind when I asked the question–would be
for creating a thumbnail. Should have tried it out before asking, works like a charm.
(This is a bit off-topic, but I’ve tried the WP support forum and haven’t got an answer so far, so maybe you can help? I’m making extensive use of the custom fields, and everytime I create a new key, one key is kicked off the dropdown-menu, keeping the number of menu items always at 10. I have to retype keys I had created earlier, because they vanish from the list. Are you familar with this? Do you happen to know a fix?
Thanks in any case.)
Andrea: So you’re all set with the use of the plugin?
As for your WP question, I looked into it and saw where the “problem” is located. The list of custom field keys is limited to 10, as you discovered. It’s hardcoded, so to change it you’ll need to modify a WP file. Look at the file
wp-admin/admin-functions.phpand search for “function meta_form”. In that function you’ll see a bit that saysLIMIT 10. Change the 10 to another number to up the number of keys presented in the list.Your support request gave me the idea to address that issue, and some others, in a new custom field manager plugin that I already had plans to create soon.
I just replied to my own post in the support forum. Found the code all by myself (I’m so proud) and increased the
LIMITvalue. Thanks very much for looking into it, anyway.And yes, all set. You could also say, “addicted”. It lets me add bibliographical data, internal and external links and pictures to my little archive and easily control the presentation of that data by shuffling around some lines of code in the index file (and CSS, of course). Gush, gush, gush.
The only problem right now is that I’m displaying most of the meta in a sidebar outside The Loop, so it messes up the layout a bit on pages that display more than one post. I’m waiting for the release of a stable 1.3/1.5 to set up templates for different kinds of pages, until then I can put up with that little inconvenience.
Hi, just wanted to let you know that I got rid of the problem mentioned in the last paragraph above by restricting the display of outside-the-Loop metadata to pages that contain only one post. A kind soul helped me with the necessary PHP stuff.
Strange, but true. I don’t know if anyone else is experiencing this but figured this place would be the best to ask.
I am trying to used this with the “Vesuvius WordPress Interface 1.20″ - the plugin works great in the main section, but fails to show anything in the right panels.
I am using the same code both times, just different
Any ideas? Anyone else experience this in the Vesuvius template?
Fantastic plug-in.
A quick question: I have put in a rather long article on the custom field, and it presents it and all. However, the hard breaks at the end of lines are eliminated, and the whole article becomes one long run-on series of sentences. How could I make it preserve the hard returns? I’ve looked at filters, but it seems somewhat confusing as the documentation in them in wordpress appears a little limited.
Thanks very much for your help.
A closely related question: is there a way to make a little link appear, which when you click suddenly opens a simple window with just the content of the custom field? I’m planning to paste an article in the custom field so you can imagine where this is going…
Thanks again!
I just installed this under wp1.5 but I can’t get it to work - nothing is showing up.
I added a key called mood with a value of happy.
<?php echo c2c_get_custom('mood'); ?>I added that within the lopp but nothing is showing up. Anyone get this to work under 1.5?
Jonah: I haven’t used Vesuvius and haven’t had anyone report a problem.
Stephen: This plugin supports filters specifically geared toward custom fields, however, in its current implementation it applies the filter(s) to all custom field values, not just any specific one. So one suggestion would possibly be to use WP’s wpautop (i.e. add
add_filter('the_meta', 'wpautop');to the filter section at the end of the plugin file), but that may adversely affect the display of other custom fields, if you use and display others. I’ve now added a task to my ToDo list to allow more fine-grain filtering of particular custom fields.As for your popup request, it can certainly be done, but requires more time to explain than I can currently give. Someone on the WP support forums might be able to answer your question.
Michael: I hadn’t tested it on WP1.5 despite having made what I thought was the necessary changes to have it work under 1.5. Since you said something, I went and looked and spotted a problem for the
c2c_get_recent_custom()function:should be:
However, that doesn’t explain why
c2c_get_custom()wasn’t working for you. Later tonight I’ll test it out on my test WP1.5 install.I’m trying to use this plugin to automate a user picture since I have 2 authors on my site. Is there anyway I can incorporate the php for the author along with this plugin so that it’ll read which author it is and automatically give it the corresponding image? I got it working with the custom field value, but for that, I’d need to go in and manually set the pic everytime instead of having it automatically read.
Lawrence: If you can wait about a week, I’ll probably releasing a plugin that handles author images in an automatic, and also configurable, manner. I actually have it completed already, but have to do the mundane things related to actually releasing a plugin. Plus, it’s part of a more concerted plugin-release plan!
Do you happen to be running WP 1.5? My plugins are all going to be geared toward 1.5 from now on, though this particular one could be backported fairly easily.
WordPress as your personal information manager. Part 3 of 5.
Part 3 in a series of WordPress tutorials: assigning custom metadata to your entries.
Just as an FYI, I had c2c working flawlessly in 1.2 mingus. I upgraded to 1.5 strayhorn, activated the plugin, and everything is working flawlessly without any editing.
Just wanted to say thanks for this marvelous plugin working perfectly with 1.5 and no modification.
Still haven’t figured out the “outside the loop” stuff but I’ve got it inserting titles, texts and pics in my sidebar.
Wow, what an incredible plugin! I’m running WP 1.5 (brand new to it, btw) and installed 2.02 of this plugin per instructions, but when I active it, I get this error message in the /wp-admin/ header:
Warning: Cannot modify header information - headers already sent by (output started at /home/ozaaxuly/public_html/wordpress/wp-content/plugins/get-custom.php:181) in /home/ozaaxuly/public_html/wordpress/wp-admin/admin.php on line 6
Very unsightly in admin dashboard. Posted web pages are okay. Hesitant to try the function, and deactivating for now.
djchuang: That error most often means that there spaces or other characters before the
at the start of the file or after the <code>?>at the end of the file. Check to make sure there aren’t any such extraneous characters.Scott - thanks for the quick response, and didn’t know PHP files were so sensitive to extraneous chars. Your suggestion fixed it, and the plugin works like a champ! Great work, thank you!
not sure if you think there’s a way to do this. I installed the plugin and got the basic features working to give me a “subtitle” for some pages (not posts, I’m using wp 1.5). what I’d like to do is use this subtitle in the “get pages” loop so that the subtitle also displays in my navigation. any ideas? I tried appending the subtitle in the list pages function, but I get the subtitle of the page I’m on, not of the page in the navigation loop… is there a way to direct the function to check a specific page and not the current one? I’m just getting my feet wet with php and wordpress, but I am a web developer and the basic concepts are the same as other languages I’ve used…
[…] utput of the the_meta(); tag. Fortunately, Scott Reilly at code2coffee has already written a plug-in to handle it. Yay! This entry was posted […]
Im using this on my site with WP version 1.5 It seems to work ok except i used it to call my mood plugin. I placed the c2c call code inside my index.php page. I put it in the wrong place and so i moved the code lower so it would show up after my postings and not before. But it doesnt seem to want to move. Even after i moved the code and updated my page its still showing up right beside the date. Ugh! What do i need to do to fix this??
Can you use HTML within the custom fields? Will it appear? Images for example. How do I display images within the field?
Hi Scott,
I can’t get my custom fields to show up when I search. This is what I have:
Many thanks,
Ross
I have the same problem as Ross does. I looked at:
http://wiki.wordpress.org/SearchMetaPostData
But my wp-blog-header.php file doesn’t have a line 485, nor does it have the string $search in it. I’m not sure if that trick is only for 1.2 or what. I have 1.5
Ditto the above 2 people. I would also like to know how to include the info stored in the custom fields to show up in the search results.
I found a way to search the custom fields!
http://randomfrequency.net/wordpress/search-meta/
[…] refox link prefetching jam, the votio plugin, gamerz polls, and using the amazingly simple get custom field values for each ad’s magazine info. Mets lost their fir […]
Hi Scott,
I would like to know is possible to use this plugin for calling two type of images to a post? For example on my regular post on the frontpage (index.php) which has several posts. If a visitor click on the title link it will bring them to a full single post which has a full size image on single page with all the text of the post, instead of small image on the frontpage.
Thank you
~Rocky
I’m looking to use this plugin to display a set of custom field values in each post. Before doing that, i need to have the custom fields be fixed on each edit-form.php page, not simply for a single post. This post looks helpful, except it was for 1.2, and i dont know if the code needs redoing.
I have tried, and still am, to incorporate multiple inputs such as the content etc.. but am not getting very far with it.
Any help would be greatly appreciated
Thanks,
Amory
shawn: Still looking for an answer for your request?
Java Where precisely did you move the c2c_get_custom() function?
trench: Yep, you can use HTML in custom fields. For something like an image, it depends on how you want to reference them. Are they always in the same directory? If so, send the link tag stuff in the $before and $after arguments and just put the image name in the custom field.
<?php echo c2c_get_custom('image', '<img src="http:// www.7milesdown.com/wp-content/images/', '" />'); ?>Otherwise, put the full path in the custom field and omit the directory information from the $before text.
Ross, Nessie, hcm: Yes, currently WP does not search into custom fields. And for various reasons, it may never. The trouble is that not all custom fields are meant to be publically available.
Rocky: With a small bit of coding you can accomplish that. Here’s an example (which may not be exactly what you wanted):
In index.php where you want the image to appear (I’m assuming the small and large images are to appear in the same spot:
Assumptions:
* Large and small image show up at same spot in post
* Large image appears on single page; small appears on all others
* Image filename in is ‘post_icon’ custom field
* Image location is /wp-content/images/
* Large file is something like myimage.jpg
* Small file has same name, but with “-sml”: myimage-sml.jpg
There are a ton of other ways to do this though.
EXACTLY what I wanted! I’ll try to make it work!
Kudos to you!
I give a try tonight and I am at work right now. So if Kaly get it to work before me. Please provide link so we can test it out. Again thanks Scott.
Scott,
I put this code “”);
?>” in my index.php page and when I write a post I insert the “myimage-sml.jpg” in the post. In the images directory there are also the file “myimage.jpg”
I also add the “post_icon” in the custom field when I write the post. But the post and the single page show the same image, instead of the small and large in teh single post. What other steps have I miss?
Thanks
Scott, look like Wordpress strip my the code from the post. Anyway is the code you post for me. How do you put code to showup in the post anyway?
Thanks
Scott,
Here is the code I put in the index page and what other steps I have to do?
Thanks
Rocky
[…] wn spambots. It goes far beyond User-Agent and Referer, however. Plugins to Check-Out Get Custom Field Values Supposed to be able to create a ‘Currently Readin […]
[…] ack of plugins that look interesting but I have not had a chance to look into in detail. Get Custom Field Values Supposed to be able to create a ‘Currently Readin […]
[…] looks like some of the best plugins . Will probably install some right away. Plugins Get Custom Field Values Supposed to be able to create a ‘Currently Readin […]
I installed your plug-in, seems to work fine (thank you by the way), but now when I go to manage my pages it is blank…I can still write posts, but the manage posts page is blank. Any thoughts?
From the perspective of your close knowledge of the custom tags implementation, have you been thinking of a mechanism allowing to posts by the value of one of their custom tags?
This would make “timed” posts possible - which is now not possible as we can not create a post with a set date.
I know that this would have to influence the Loop and maybe override some of the sorting functions in it but would be very valuable and provide great flexibility.
Bonus functionality would be to:
- only show posts with a certain value in a custom field
- only show posts with a certain metadata key filled in
Thank you.
Scott,
First of all, thanks for writing this. It may save me some time with a current project, but even if it doesn’t I can see all sorts of uses for it.
Second, I want an array of values for a given field so I can play with the data in php. Possible currently? If no, I’ll hack my own. I haven’t gotten into the code yet to see how this works.
Thanks.
[…] os”>smugmug account - the plan is for this to be super-automatic in future. Kudos to Scott Reilly for writing a handy pl […]
[…] dass es nicht auffällt aber merken hilft. Orientierungshilfe: Expertenlevel integrieren (Get Custom Field Values) to be continued Außerdem: Funktionalität kont […]
I just figured out how to only post the custom data if custom data exists. Here’s my example code…
There’s undoubtably a better and more elegant way to do it though.
my earlier post left on the question mark php stuff and isn’t showing up.
[…] nt is you’re supposed to look and click under that. Exploiting Scott Reilly’s Get Custom Field plugin, I present to you my twisted Currently’s: Reading […]
[…] children. Free that poor girl from Tom’s creepy clutches! (tags: Humor Celebs) Get Custom Field Values Uses the custom fields option on each Wordpress post a […]
[…] ut what’s what.
Behind the scenes, I’ve also hacked up Scott Reily’s Get Custom Wordpress plugin to retrieve the latest post in a particular categor […]
[…] East Coast of US, I hope | -400 This is a test for a new (to me) WordPress plugin, Get Custom Field. I’m going to try to add some stuff to make custom fie […]
This plugin looks very nice. I think it’ll enable me to have a blog with different times… in multiple time zones (different posts display different time zones—and locations).
But (because I’m such a know-nothing when it comes to PHP) I don’t know how to get from creating the custom field tz with, say, a value of -6, and from there calculating to make the time displayed in that post to be accurate for the local time zone. (Do I create a new time variable $time_zone_time ? Or do I perform some calculations based on the value in ‘tz’ and then manipulate or pass something to the the_time() tag?)
I’ve also queried on WordPress support board in this post.
Hello,
I’m using this plugin in Wordpress (WP 1.5.1.3) for an events site, and it gives loginproblems. Whenever I activate the plugin I can’t logout anymore and only get to see blank pages throughout the site (wp-part => blank login, blank admin, blank post etc.), except for the blog itself. When I remove the plugin from the plugins folder everything is OK again. Also when I upload the file again but leave it deactivated no harm is done. But activating it will close all acces to WP.
Any idea? (I’m not using any other plugin).
Jack
I noticed there was 1 space behind the last ?> php-code. I removed it and (untill now) it seems to be working again.
Can 1 space really make the difference?
Thank you - this is great.
Hi there…
This is a great plugin, Scott. Many thanks!
I have a question about the sample code you posted above…
', 'blank'); ?>I find this works correctly for the first page (e.g., http://example.com/), but for subsequent pages (e.g., http://example.com/page/2/) I just get the ALT text.
I can correct this buy specifying the full path to the icon in the SRC attribute (e.g., src=”http://example.com/wp-images/posticons/”, but it doesn’t work with src=”/wp-images/posticons”. I’m not very knowlegeable about PHP. Is there another way of using the WP tag that would work here?
Well, hmmm… I guess I can’t put great-than or less-than characters into comments, but I was referring to the Post Icon code at the top of this page.
Hi Scott,
In scanning through this page I noticed a request from Joey Horne on October 19, 2004 that is similar to what I want to do.
You later indicated that it could be done, but I have not been able to find any further reference to it.
I want to filter my Comments on my Static Pages. (Not Posts).
For example, I would like users to be able to filter comments based on, say, the Commenting Members zip code (entered in the Custom field at the time of comment) or their own zip code. (Or can this be done dynamically from the WPDB through your plug in?)
But this would also be cool for say Posts to a ‘what’s on’ blog so that user’s could see ‘what’s on’ for a particular Geographical area.
The ability for them to edit a preference to “retain” the filter during subsequent visits through either cookies or your plug-in would be nice - so long as they can override those preferences at any time ‘on-the-fly’ or to change and re-set them.
Aplogize for the long shopping list - seems like your plug-in may help but I am lost on how to make it work.
TIA
Hi Scott,
In scanning through this page I noticed a request from Joey Horne on October 19, 2004 that is similar to what I want to do.
You later indicated that it could be done, but I have not been able to find any further reference to it.
I want to filter my Comments on my Static Pages. (Not Posts).
For example, I would like users to be able to filter comments based on, say, the Commenting Members zip code (entered in the Custom field at the time of comment) or their own zip code. (Or can this be done dynamically from the WPDB through your plug in?)
But this would also be cool for say Posts to a ‘what’s on’ blog so that user’s could see ‘what’s on’ for a particular Geographical area.
The ability for them to edit a preference to “retain” the filter during subsequent visits through either cookies or your plug-in would be nice - so long as they can override those preferences at any time ‘on-the-fly’ or to change and re-set them.
Aplogize for the long shopping list - seems like your plug-in may help but I am lost on how to make it work.
TIA
Hi Scott,
I’m wondering if this might be useful for pulling the contents of meta fields within pages into the wp_list_pages function. I’m hacking together something where I’d like to be able to list those pages by data stored in the meta fields, and this might do it.
Unfortunately, I seem to be getting errors when I try to activate the plugin, so I haven’t yet been able to check it out.
Does this sound like something this can do - i.e., pull custom fields from multiple pages that you’re not presently on?
Thanks,
Jeremy
[…] So… I got to looking at the custom fields that Wordpress has already built in. I looked around and found a plugin by the name of Get Custom Plugin Values that allows a whole lot of customizing using a few simple calls. This sucker rocks!! […]
[…] coffee2code.com » Plugin: Get Custom Field Values […]
[…] coffee2code.com - Plugin: 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. […]
Hi Scott,
Thanks for this amazing plug-in. I have a question for you, that is sort of answered in Post #81, but I still can’t figure it out. Here is what I am looking to do: I would like a small graphic to show up and be linked to something (say, a popup window). Is there a way to add an href link into Value field of a custom key?
Thanks for any help, Jesse
scott-
very nice plug-in. although i’m wondering if the plugin is the way to solve my situation…maybe you can help. i’m wanting to run a poll on certain posts tied to the post…what i do is create my poll which assigns it an id#. i have the poll code inserted into my post-template to display the poll…when i add a post, i select a key named ‘poll’ and then input the value (#) that corresponds to what poll I want to display on that post. i’m using Advanced Poll 2.03.
here’s the line of code I need to be dynamic because if it’s static then the same poll is displaye on all my posts since it’s in the post-template :
echo $php_poll->poll_process(4);
as you can tell above the number i need to have dynamic is the ‘4′…the post i’m working on i select the key named ‘poll’ and input a value of ‘4′…i then put the following code in my post-template.
echo $php_poll->poll_process();
…but the result I get is : Parse error: parse error, unexpected ‘poll_process(”);
…but the result I get is : Parse error: parse error, unexpected T_STRING in /home/mynotary/public_html/wp-content/themes/default/single.php on line 41
finally, i tried :
echo $php_poll->poll_process(echo c2c_get_custom(’poll’));
…but the result i get is : Parse error: parse error, unexpected T_ECHO, expecting ‘)’ in /home/mynotary/public_html/wp-content/themes/default/single.php on line 41
any ideas or is custom-fields not the way to get what I need done? is there another way to achieve what i need? i’ve tried many resources for days now and have found no answer.
This plug-in is amazing. I have successfully incorporated it into 2 of my websites. I have ran into a problem though. For my latest site, I tried to use the plug-in with MULTIPLE LOOPS. What I’ve done is this:
is there a way to use TWO fields within the retrieve functions? I have two meta keys ‘news source name’ and ‘news source link’ for each of my posts….
Basically for my posts I want to give credit to a news story from the link I got it from, so in my posts template I would it to pull the news source name (if there is one, eg Fox news) and turn it into a link to the article (from the news source link). If there is no name and link then I don’t want anything to show??
[…] Bad Behavior (as previously noted - only two comment spams since installation) Easier custom field insertion when writing posts Easier display of custom fields in posts Random Quotes […]
Hi - is there any way to pass the value generated by c2c_get_recent_custom into a link that will automatically search WP entries for that value?
(I’ve altered my WP install so it searches custom fields, and I have verified that it works. I can generate a list of values from the c2c_get_recent_custom command, then copy/paste a value from the generated list into search and get the results I want. )
It works “by hand,” but the only thing I don’t know how to do is to make it so that when the list is generated, it automatically creates a link for each item on the list that, when clicked, would automatically perform a search and take the visitor to the search results page.
I understand if this can’t be done or if an explanation is beyond the scope of this forum, but figure it doesn’t hurt to ask. Thanks!
[…] 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! […]
I don’t know if anyone has ever had this problem, or know why this is happening, but when I have inserted custom meta data into my category loop, the appropriate data doesn’t always display.
I’m not a programmer, so I don’t know if this is strange or not. I’m running 3 loops on my categories page that filters posts according to certain custom data fields using two plugins (custom field gui and AH Select custom). That part is working fine (I think).
I also have meta data that displays custom field datausing the plugin. What’s strange is that in some of my posts, the meta value just doesn’t seem to get displayed. To see for yourself, check out:
http://radresearch1.odani.com/?cat=5 and
http://radresearch1.odani.com/?cat=6
Does anyone know how this might happen??
I would like to sort posts by the value of a particular custom field. There does not seem to be an easy way to do this. Though I realize this is outside the immediate scope of your wonderful plugin, it seemed like a good starting place to ask.
Perhaps there is a way to hack WP’s built-in query_posts(orderby) attribute, which only seems to support ‘author’, ‘date’ and ‘title’ as values.
(I’ve also posed the question in a bit more detail on the WordPress support forums.)
Thanks for any ideas or suggestions,
abrupt
I realize this is outside the scope of this plugin, but… I have a clip blog on my site, meaning that each post has (as a rule) a URL in the body. Right now, I generally post using the bookmarklet and bookmarklet.php, which puts the URL in the body (in my case, using Textile markup). What I’ve been trying to do is find a way to insert that URL into a custom field called clip_url instead. The reason I want to do this is, if I want to change the way the link looks after posting, there’s no easy way to do that right now. Since it’s part of each post’s body, it’s sort of static. Where if it were a custom field, I could simply edit the current theme to change the text of the link, the position of the link, etc…
Has anyone found a way to post custom links from the bookmarklet? I’ve made a few attempts to do this, but so far everything has failed. If I add the custom field by hand in the main post editor, everything works fine with the get custom field plugin… I just can’t convince the bookmarklet post method to stuff this value into a cusotm field for me
Might you have any explanation for why my new Custom Fields - after working normally for quite some time, and with your plugin - no longer get recorded in the database and so do not show up in the pulldown menu? I have searched the WP fora and posted the problem, but to date with no answers. Thanks for any help or suggestion. Regards
[…] Today’s Mood: Jolly and Happy y puedes darle un estilo usando css. Puedes encontrar m?s informaci?n aqu?: Using custom fields Al ponerme a usarlo me di cuenta que no me serv?a, ya que esos campos solo sirven para a?adir un contenido dentro de los posts, dentro del wp-loop. Yo necesitaba las variables para fuera del loop de los posts, para a?adir un bloque de contenido con un plugin en una plantilla. As? intentando solucionar este problema encontr? este plugin con el que puedes usar esos campos en cualquier parte de tu plantilla. El plugin se llama get custom value. Adem?s de los valores del campo puedes pasar html para poner antes y despu?s, asi que puedes darle tambi?n estilo tambi?n. […]
Hello, nice plugin
I’m trying to use it in conjuection with c2c_get_recent_posts but am not sure if it can work in this context?
Eg. I would like to add two custom field values to my sidebar, after the post URL which I’m pulling out like this:
Exhibitions
%post_URL%”, “4″); ?>
Is this possible, I’m not sure reading the above!???
Sorry that code should have been:
%post_URL%", "4"); ?>Sorry about the mess above, hopefully you can prune out the junk, thanks in advance and sorry for the hassle.
[…] Da die Ausgabemöglichkeiten über Template-Tags bisher eher spartanisch sind, bietet sich eine Extension an, mit der man alle Felder einzeln ansprechen kann: get_custom_field_values. [&