Taxonomy Details Out of Loop
I added a new function to Ultimate Taxonomy Manager to enable access of values outside the loop.
The function accepts three variables
xydac_cloud($taxonomy,$termslug='',$field='')
1. Taxonomy name
2. Term Slug (Optional)
3. Field Name (Optional)
Only Taxonomy
If you provide only Taxonomy
xydac_cloud('project','','project-lang')
then you get result as an array with array key being the term slug.
[gatepass] => Array ( [name] => Gatepass, [description] => Gatepass Management System, [project-name] => gg, [project-lang] => C# [project-members] => sxsxdsdx ) [taxonomy-manager] => Array ( [name] => Taxonomy Manager [description] => Taxonomy Manager [project-name] => pop [project-lang] => PHP [project-members] => ) )
As you can see i have added name and description of the term so you can retrieve them also.
Taxonomy Name and Field Name
Now if you provide Taxonomy name and Field Name as
xydac_cloud('project','','project-lang')
then you get resualt as a similar array but fith fields only being the one you supplied.
[gatepass] => Array ( [project-lang] => C# ) [taxonomy-manager] => Array ( [project-lang] => PHP )
Taxonomy And Term Slug
Now consider you supplied taxonomy name and termslug
xydac_cloud('project','gatepass')
Now you get complete details of the individual term
[name] => Gatepass [description] => Gatepass Management System [project-name] => gg [project-lang] => C# [project-members] => sxsxdsdx
Taxonomy Name, Term Slug, and Field Name
Now Consider you supplied Taxonomy Name and Termslug and Field Name as well
xydac_cloud('project','gatepass','project-lang')
Now you get the value of the particular field of the perticular term in the particular Taxonomy with no array involved.
string(2) "C#"
This is useful, but can you provide some examples?
I don’t have much knowledge of PHP, but this was a good way for me to learn. I learn the best from examples. 🙂
PS. I made a small donation to you last night! ^_^
Thanks for always being so helpful.
@amrayu : You can use the PHP function xydac_cloud which returns and array of values. You will need to retrieve these values when using the function. Try using
when you want to know about it. you can use any variable_name here.
Now to store the returned array in a variable you can write :
Now to retrieve the value of project language as shown above you can write as follow
Let me know if you need further help.
Check out the following link for help on PHP ARRAY(http://php.net/search.php?pattern=array&show=quickref)
And Thank You very much for you Donation.
Regards,
-XYDAC
I like this post, thank you.
Hello XYDAC
I installed your plugin and mucked around a bit. Very nice. The fact that you allow for adding custom fields is a great idea. However – and before I go hacking into your code myself – I’d like to suggest that once the HTML is stripped out when writing to the table that it be stripped back in again when pulled out.
In short, I want to have a field that I’d like to contain HTML. I understand why you don’t write it to the DB but PHP does allow you to convert it back again, correct? Do you think you can add that? How soon?
Please email me and let me know what you think. As I said, if it not something you can tweak in soon then maybe you can point me in the right direction to do it myself. I’m not trying to be pushy. Just make a client happy before the holidays 🙂
Thanks!
Mark
p.s. Also, when you email me, I’ll explain why I’d like to use HTML. It’s a bit unorthodox but I think you’d appreciate it. It just doesn’t seem necessary for the immediate discussion.
I have created custom taxonomy meta data.. the taxonomy is called actor and the meta is called twitter…how do I fetch this inside my loop? I want to fetch it using my template file and not shortcode in post..
Thanks
Put this in Ultimate-Taxonomy-Manager.php
if ( !function_exists(‘funct_GetTaxonomyField’) ){
function funct_GetTaxonomyField($str_PostID, $str_TaxTerm, $str_TaxTermField){
$arr_UTM = xydac_cloud ($str_TaxTerm,”,$str_TaxTermField);
$arr_GetTerm = wp_get_post_terms($str_PostID, $str_TaxTerm);
$str_ReturnStr = ”;
foreach ($arr_GetTerm as $arr_GetTermRow) {
$str_ReturnStr .= htmlspecialchars_decode($arr_UTM[$arr_GetTermRow->slug][$str_TaxTermField]);
} // end foreach
return $str_ReturnStr;
} // end function
} // end if
Then call it like this from inside of a loop:
echo “This post’s special taxonomy meta:” . funct_GetTaxonomyField($post->ID, ‘my-taxonomy-slug’, ‘my-taxonomy-custom-field-slug’) . “”;
Credits to Mark Simchock: http://www.chiefalchemist.com
I have created custom taxonomy meta data.. the taxonomy is called actor and the meta is called twitter…how do I fetch this inside my loop? I want to fetch it using my template file and not shortcode in post..
Thanks
I Guess that the best way would still be to use short codes in the template files.
Feel free to ask me for further help.
-Xydac
How do you get the termslug from single page?
[…] taxonomy albeit without much luck. I’m using Taxonomy Manager to create my meta data, which does have functionality for echoing this but it outputs it as an […]
I suggest this patch:
In (taxonomy.php: function xydac_cloud($taxonomy,$termslug=”,$field=”){)
– $terms = get_terms($taxonomy);
+ $terms = get_terms($taxonomy,’hide_empty=0′);
To get all taxonomy!
Great plugins 😉
thanks i’ll add it in next ver
Great plugin! I would like to know the php line to put in my code to display the current post’s custom taxonomy (in single.php)?
Thanks!
Peter
XYDAC – How can I loop through the taxonomy and pull every image out? Attempting to do it with:
$terms = get_terms(‘users’, $args);
However, it won’t let me pull user_avatar because it isn’t one of the options.
Figured it out… Here’s the loop I used to build a list of the avatar images if anyone else is interested:
‘users’, ); $terms = get_terms(‘users’, $args);
$count = count($terms); $i=0;
if ($count > 0) {
foreach ($terms as $term) {
$i++;
$term_list .= ‘slug . ‘”>slug.”,’user_avatar’) . ‘” width=”50″ height=”50″ alt=”‘ . $term->name . ‘” title=”‘ . $term->name . ‘”/>‘;
}
echo $term_list;
}
?>
Hello XYDAC,
Your plugin is great! I have a question: How can I have a custom fields value for a given term from code when there is no posts associated with that term?
The xydac_cloud works great, but only after joining a post to my terms – which is completely logic.
Thanks
Hi Veres,
It’s been quite some time since you posted your question, but I came across the same requirement today, and found a solution, so I am sharing with you and anyone else who need it.
If you would like to be able to retrieve a list of items from your custom taxonomy, and you would like that return to include items *that are not associated with any page/post/etc* then here is your solution:
In WordPress, this is done by passing “hide_empty=0” in a get_terms() call like get_terms(‘taxonomy_name’, ‘hide_empty=0’). As it turns out, the function xydac_cloud() utilizes get_terms(). I have added the following to the code in ultimate-taxonomy-manager/taxonomy.php on line 348 (where the definition for “function xydac_cloud(…” begins) and successfully been able to return items with no associated post/page:
————————
REPLACE lines 348-350 with the following 3 lines:
function xydac_cloud($taxonomy,$termslug=”,$field=”, $args=”){
$result=array();
$terms = get_terms($taxonomy, $args);
————————
(the only actual changes above are adding the optional $args=” var to the method, and then adding that to the get_terms() call below)
————————
WHEN YOU MAKE YOUR xydac_cloud() call, pass it the arg you want – in this case, hide_empty=0:
$allitems = xydac_cloud(“[taxonomy_name]”, “”, “”, “hide_empty=0”);
————————
Hope this is helpful to someone
hi. thanks for this great plugin.
what must i do that it works in header.php?
hello,
I have set up a taxonomy called “essence-types” which has basically 2 values
“essence1” and “essence2”. I like to put in a query in my functions.php file that that gets the value of “essence-types” from the current post and then stores it into a variable $essenceType.
I tried:
$terms = get_the_terms( $post->ID , ‘essence-type’ );
$essenceType=$term->slug;
but that didn’t work. Any help or hints would be greatly appreciated!
Put this in Ultimate-Taxonomy-Manager.php
if ( !function_exists(‘funct_GetTaxonomyField’) ){
function funct_GetTaxonomyField($str_PostID, $str_TaxTerm, $str_TaxTermField){
$arr_UTM = xydac_cloud ($str_TaxTerm,”,$str_TaxTermField);
$arr_GetTerm = wp_get_post_terms($str_PostID, $str_TaxTerm);
$str_ReturnStr = ”;
foreach ($arr_GetTerm as $arr_GetTermRow) {
$str_ReturnStr .= htmlspecialchars_decode($arr_UTM[$arr_GetTermRow->slug][$str_TaxTermField]);
} // end foreach
return $str_ReturnStr;
} // end function
} // end if
Then call it like this from inside of a loop:
echo “Essence1 Value:” . funct_GetTaxonomyField($post->ID, ‘essence-types’, ‘essence1’) . “”;
Credits to Mark Simchock: http://www.chiefalchemist.com
Hy,
Thanks a lot for your great work. I try to use xydac_cloud() function on the nativ taxonomie in wordpress : “category”.
It works great but when I try to access a sub-sub category, wydac_cloud doesn’t find the term.
Example : if I use xydac_cloud(‘cateogry’,”,’on-line-sale’);
– category is the name of the nativ taxonomy in wordpress
– “” left it umpty cause I want to check if my category “formulaires-douaniers-vel” is in the returned array(),
– “on-line-field” is my field containing data.
The function returns me a liste of terms, but the one i’m looking for. In fact, it doesn’t any of the categories that are under 2 hiérarchical depth.
“Douane” > “vel” > “Formulaires douaniers” > Formulaires douaniers vel > (and there’s more sub level of depth…
Could you please help me ?
Hi,
I have this working outside of the loop which is great:
$var = xydac_cloud(‘bonus’,’existing-accounts’,’anothertest’);
echo $var;
I saw on the shortcode version there was an option to add ‘decode = 1’ to return an html version – is this possible in my code above?
Thanks for any help
Hi Chris,I am afraid there is no such predefined option in this function. Regards,-Xydac > Date: Mon, 4 Mar 2013 00:57:08 +0000 > To: indk@live.in >
Thanks for the plugin!
I’m trying to display a custom field on the tag page. I’m using the xydac_cloud function. However, all it returns is simply Array.
echo xydac_cloud(‘post_tag’, ”, ‘disclosure’);
Any ideas what I might be doing wrong?
When I use the function xydac_cloud, my page takes a few more seconds to load.
In my case, I just want to show a custom field for a particular tag. WordPress functions are faster 🙂
$result = get_metadata(“taxonomy”, $tagid, $field , TRUE);
echo $result[‘customname’][0];
Where $tagid is the id of the tag, and customname is the name of the custom field.