Categories
Package/plugin/module WordPress

Get Custom Field Values v2.5

I’d like to announce the official release of the updated Get Custom Field Values plugin (v2.5).

Easily retrieve and control the display of any custom field values/meta data for posts, inside or outside “the loop”.

The plugin’s official homepage is located at :
coffee2code.com/wp-plugins/get-custom-field-values.

Highlights

This plugin has been faring well despite its nearly four years of life, even after many updates to WordPress. This latest release brings with it full compatibility with WordPress 2.3+ and 2.5 (with continued support for 2.1+ and 2.2+).

This update is part of coffee2code’s 14 Days of Plugins (updated plugin #2).

Comments welcome on this post for this version of the plugin. Comments will be closed once this release has been superseded by another.

Read on for a detailed ChangeLog of the release.

Detailed ChangeLog

These are the detailed changes, which may or may not make sense to you depending on your familiarity with the previous features and internals of the plugin.

  • Modified SQL query code for c2c_get_recent_custom() to explicitly look for post_type of ‘post’ and then optionally of ‘page’
  • Per-custom field filter name is now made using a sanitized version of the field key
  • Minor code reformatting
  • Removed pre-WP2.0 compatibility and compatibility checks
  • Changed description
  • Updated copyright date and version to 2.5
  • Added readme.txt
  • Tested compatibility with WP 2.3.3 and 2.5

30 replies on “Get Custom Field Values v2.5”

[…] Get Custom Field Values v2.5: This updates Scott’s popular Plugin for WordPress 2.5 and recent versions to retrieve and control the display of custom field values and meta data for posts inside or outside of the WordPress Loop. Most custom fields must appear within the WordPress Loop, and this Plugin helps break the barriers, giving a WordPress Theme designer or blog owner more options on what content goes where. […]

Sorry, I have looked through all your documentation and Googled for help but I cant understand why the custom field isn’t appearing on my page.

I put it in my sidebar.php to change the displayed weather which is defined by a letter…. A, B, C etc.

I have the following code:

<?php if(function_exists(wp_forecast)) {
wp_forecast( “” );
} ?>

and obviously I have a Key of ‘weather’ and ‘A’ as the custom field’s value however its just not working…

I also just added to the homepage.php (template for my home page which has the custom value set) and still no ‘A’ appeared on my page.

can you please please please shed some light on what I am doing wrong.. it seems like its meant to be very simply but I’m just not getting it.

thanks very much

sweet program!

I was wondering if there’s any way to make the variable show up for the search engine. I’m trying to have the search pull up from post.php…

I need the results to appear in the search results. Any ideas?

-Stu

Hi Scott,
Thanks a lot for updating Get Custom Field Values.
It’s Invaluable.

Just a query regarding your own example for displaying a (post_icon) picture, which apparently cann’t find your wordpress.gif: is it your example code at fault or is it the absence of your .gif file? I ask because I’m trying to implement this and I’m not succeeding: my gif never displays.
Thanks again

Hi, Scott. I’m excited about the use of this plugin. I have one question though. I would like to use this plugin to display the corresponding image on each Page I have. I’ve created the key as ‘header’ and the value is the path/to/image. Then in my header.php file I have the foolowing

<style type="text/css">
#header {
background-image: url("<?php bloginfo('url'); echo c2c_get_recent_custom('header'); ?>");
}
</style>

This reads the same value for each page I’m on. If have a Page called ‘home’ and a page called ‘about’ I get the ‘home’ value on the ‘about’ page as well. Am I doing something wrong? Thank you!

Hi…!
I recently upgraded all our sites to WP2.5, and a neat little plugin called keywords 1.0 no longer works … this used to allow me to echo the custom field called keywords in places like the header template. I’ve put the following into the template but it won’t print, like so
<?php echo c2c_get_custom('keywords'); ?> but it doesn’t print anything out. I tried the get_recent_custom and that works, but it grabs the data from the most recent post, not the current post field. The echo works fine when printed on the actual post itself, such as within the body of the index.php template.

Sooo.. not sure how to get this to work to pull the current post custom keywords field data into the header and have that print for the current page. Use a function call? Doh. My make a donation finger is all ready to send you some moola if you can help answer that/this.

Love the plug-in for post pages; just trying to get that data into the header on a per-post basis, within the header.php template. Hope that made sense!

Thanks!
Chris

Erik: Keep in mind that c2c_get_recent_custom() gets the most recent value of the custom field (based on the related post’s date). So the result you were getting from the usage you mentioned is the correct value it was meant to get (regardless of what page you’re on, the most recent ‘header’ will be the one retrieved).

You are actually trying to do something outside the scope of the plugin. c2c_get_recent_custom() isn’t aware of what post you’re on (since it just looks for the latest value of the custom field) and c2c_get_custom() only knows about a single post when “in the loop”, which in header.php you aren’t.

Try the following in your header.php instead, though I don’t claim this is the best way to go about doing this:


<?php if ( is_page() || is_single() ) :
    global $id;
    $id = $post->ID;
    echo c2c_get_custom('header',
      '<style type="text/css">#header { background-image: url(' . get_bloginfo('url'),
      ') }</style>');
  endif;
?>

I see now. I thought that was what was occurring but i was unsure. Your example works perfectly. I do have one question in your code – is the first line supposed to read “… || is_single()…” ?

Thanks again!

Erik: Yep, you’re right. I mis-typed. I was re-keying the code that I tested on another machine. Typo fixed. Thanks.

Erik, Chris: Due to your similar requests, and that of others, I’m going to be releasing an update of this plugin to handle the situation you guys are asking about. For example, the hacky bit I gave Erik to use above will now be able to be done with just:


<?php echo c2c_get_current_custom('header',
      '<style type="text/css">#header { background-image: url(' . get_bloginfo('url'),
      ') }</style>'); ?>

(This is in place of the entire PHP block of code I included a few comments back.)

Stay tuned…

since i installed wp 2.5.1 i can’t write new posts because the c2c get custum script causes an unresponsive error. Is this a known issue?

Sorry, the error was caused by the database. I imported the posts (also existing posts). But this import also made new records in the wp_postmeta table with a postid 0.

After running this query the problem was fixed:
DELETE FROM wp_postmeta WHERE post_id = 0

Hi Scott, love the plugin. Having one problem. I have the custom field “Email” to display email addresses. Using the below code it displays right as a clickable link, but though it opens a new email it’s not inserting the email address in the “to” field.

<?php echo c2c_get_custom(‘Email’,’‘,’‘); ?>

It just prints “Email” in the “to” field instead of the actual address.

thanks

Michael: It looks like you want to display the “Email” custom field twice, right? Once as the mailto: value and once as the text being linked? If so, you’ll have to go about things in a slightly different manner. There are a few ways to approach it, but this is what I’d do:

<?php
  $email = c2c_get_custom('Email');
  if ($email) {
    echo "<li class='address'><a href='mailto:$email'>$email</a></li>";
  }
?>

Hi Scott,

Just paypalled you some appreciation. I have one other question. Here’s the basic query I’m using:

query_posts ('category=7&numberposts=150&orderby=title&order=ASC');

Is there any way to randomize the order?

thanks

Hi Scott,

Thanks for this powerful tool!

I need my page to behave in different ways depending on some conditions. In a few words, I have a tutorial site, and the template should be an “A” for internal tutorials and a “B” for external ones.

So I thought of using a custom field to define what is external and what is not. So I need to create some conditions, like so:

if (c2c_get_custom(‘external’) == ‘yes’) :
do this
else :
do that
endif;

I tried it but it doesn’t work. what do you advice? (that’s in the loop btw).

Wow. Thank you sooo much for this plugin! You just helped me do something with my blog that would have been really difficult without this plugin. Thank you SO much for all of your hard work. You’re a Godsend!

Hmmm, still wondering about the new version you mentioned in your comment on 24 April… Any news?

Thank you!

I was just wondering why the WordPress Extend, Plugins Directory is still showing Get Custom Field Values version 2.1?

wordpress.org/extend/plugins/get-custom-field-values/

WordPress 2.6 seems to automatically tell the user about needed plugin updates… but only if it’s up to date in the Extend directory.

Thanks for this tremendous plugin, I’ve actually been using it for about 2 years.

As a total (and I do mean total) noob when it comes to WordPress and plugins, I was able to install and aply the plugin following your instructions. I do have a question: is it possible to show a different post icon for every post, the way it’s done on LiveJournal?

Hello, I’ve been wondering if there is an easy way to call two custom fields w/in the loop. I’m using your plugin as follows w/in the loop and would like to replace the_excerpt_rss with a custom excerpt:

<item>
    <title><?php the_title_rss() ?></title>
    <image>
    <url><![CDATA[<?php echo c2c_get_custom('ep-thumb'); ?>]]></url>
    <title>Empowering People image</title>
    <link><![CDATA[<?php the_permalink_rss() ?> ]]></link>
</image>
    <description><![CDATA[<?php the_excerpt_rss(); ?>
]]></description>
<link><?php the_permalink_rss() ?></link></item>

Comments are closed.