Created
September 24, 2012 00:41
-
-
Save twright/3773601 to your computer and use it in GitHub Desktop.
Get the value of an ECF field for a comment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Get the value of an Extra Comment Field. | |
* @param string $ref The ref code of the field to retrieve e.g. 'ecf_3'. | |
* @param integer $comment_id The id of the comment. | |
* @return string|null The value of the user's response to the field. | |
* @see ecfdb::get_comment_data() | |
*/ | |
function ecf_get_field_value( $ref, $comment_id = null ) { | |
// Make use of the global variable containing the Extra Comment Fields | |
// database and WordPress comment objects | |
global $ecfdb, $comment; | |
// If no comment id has been specified, use the id of the current comment | |
if (is_null($comment_id)) $comment_id = $comment->ID; | |
// Retrieve the Extra Comment Fields data from the comment metadata | |
$comment_data = $ecfdb->get_comment_data($comment_id); | |
// Retrieve the data for the current field, if found, otherwise null | |
return isset($comment_data[$ref]) ? $comment_data[$ref] : null; | |
} | |
// Get the value of field ecf_3 for the current comment | |
$a = ecf_get_field_value( 'ecf_3' ); | |
// Get the value of field ecf_3 for comment id 4 | |
$b = ecf_get_field_value( 'ecf_3', 4 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment