- Posts: 10
COMMUNITY FORUM
How to access extra fields in author view
- Daniel
- Topic Author
- Offline
- New Member
Less
More
9 years 7 months ago #143070
by Daniel
How to access extra fields in author view was created by Daniel
Hi there,
I'm trying to show the extra fields for each item in the author view (user.php) but I'm having some trouble and I hope you can help me.
I was trying to follow the same technique that I used to show the item's extra fields in the tag view (tag.php) but there is something different that escapes me.
First difference I noticed is that in the K2 global configuration the “Layouts and views” for author pages does not have the option to enable/disable extra fields. Whereas this option is available in the tags section under “Layouts and views” as well.
In tags.php I can index the extra fields for each item as follows:
$extraitem = array();
// Extra field array indexed by field alias
foreach($item->extra_fields as $extrafield){
$extraitem[$extrafield->alias] = $extrafield;
}
Whereas if I use the same code in user.php I get an error message: “Warning: Invalid argument supplied for foreach() in...”
Then I tried to do “print_r ($item->extra_fields)” and in tags.php I get an array with all the extra fields per item as expected, however the same code applied in user.php gets me string with just the ID and value of the extra fields.
So in user.php I cannot index the extra fields with the same code that I use in tags.php since $item->extra_fields is not an array.
What can I do to index the extra fields for each item in the author view (user.php)?
I'm using K2 2.6.9 and Joomla 3.4.1
Many thanks!
I'm trying to show the extra fields for each item in the author view (user.php) but I'm having some trouble and I hope you can help me.
I was trying to follow the same technique that I used to show the item's extra fields in the tag view (tag.php) but there is something different that escapes me.
First difference I noticed is that in the K2 global configuration the “Layouts and views” for author pages does not have the option to enable/disable extra fields. Whereas this option is available in the tags section under “Layouts and views” as well.
In tags.php I can index the extra fields for each item as follows:
$extraitem = array();
// Extra field array indexed by field alias
foreach($item->extra_fields as $extrafield){
$extraitem[$extrafield->alias] = $extrafield;
}
Whereas if I use the same code in user.php I get an error message: “Warning: Invalid argument supplied for foreach() in...”
Then I tried to do “print_r ($item->extra_fields)” and in tags.php I get an array with all the extra fields per item as expected, however the same code applied in user.php gets me string with just the ID and value of the extra fields.
So in user.php I cannot index the extra fields with the same code that I use in tags.php since $item->extra_fields is not an array.
What can I do to index the extra fields for each item in the author view (user.php)?
I'm using K2 2.6.9 and Joomla 3.4.1
Many thanks!
Please Log in or Create an account to join the conversation.
- Daniel
- Topic Author
- Offline
- New Member
Less
More
- Posts: 10
9 years 7 months ago #143072
by Daniel
Replied by Daniel on topic How to access extra fields in author view
sorted, I used:
$extravar = json_decode($item->extra_fields);
$extraitem = array();
// Extra field array indexed by field alias
foreach ($extravar as $extrafield) {
$extraitem[$extrafield->id] = $extrafield;
}
If you have a better solution please let me know.
$extravar = json_decode($item->extra_fields);
$extraitem = array();
// Extra field array indexed by field alias
foreach ($extravar as $extrafield) {
$extraitem[$extrafield->id] = $extrafield;
}
If you have a better solution please let me know.
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
- Offline
- Platinum Member
Less
More
- Posts: 15920
9 years 7 months ago #143112
by Krikor Boghossian
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Replied by Krikor Boghossian on topic How to access extra fields in author view
Code seems fine.
I would not personally change anything.
I would not personally change anything.
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.