This site uses cookies and similar technologies.

If you don't change browser settings, you agree to it.

I understand

Get values from user fields anywhere

Let's say that you are currently developing a module, or editing a existing one, or maybe writing some code from your cck custom template. And you need to get the value(s) of one or some user field(s). (without any ::fieldname:: ).

You can call the code below everywhere!
$user =& JFactory::getUser(); 
if ( $user->id ) { 
   $profileId = CCK_DB_Result( 'SELECT contentid FROM #__jseblod_cck_users WHERE userid='.$user->id ); 
   $profile = CCK_GET_Value( $profileId, array( 'phone', 'city', 'nationality' ) ); 
   $user->bind( $profile ); 
}					
Then you called your field by:
echo $user->city; 
echo $user->phone; 
echo $user->nationality;					

Get values from fields anywhere


Let's say that you are currently developing a module, or editing a existing one, or maybe writing some code from your cck custom template. And you need to get the value(s) of one or some field(s) from a specific article. (without any ::fieldname:: ).
Here are 2 functions that will do the job for you............. and you can call them anywhere!

CCK_GET_Value( $id, $fields, $mode = false )

Using this function, you just need to know the article id, and from which fields you want to get value(s).
Examples:
// $id is the id of my article.
$value = CCK_GET_Value( $id, 'my_text1' );
echo $value;or// $id is the id of my article.
$fields = array( 'my_text1', 'my_text2' );
$value = CCK_GET_Value( $id, $fields );
echo $value['my_text1'];
echo $value['my_text2'];

$id - id of article where you want to get value(s) (int)
$fields - fields you are interested in (string or array)

CCK_GET_ValueFromText( $text, $fields, $mode = false )
The second one assumes that you already got the text (introtext/fulltext) of your article.
Examples:
// $content is the content of my article.
$value = CCK_GET_ValueFromText( $content, 'my_text1' );
echo $value;
$text - text of article where you want to get value(s) (string)
$fields - fields you are interested in (string or array)