Note that there are some explanatory texts on larger screens.

plurals
  1. PORecursive function to get the parent caegory description
    primarykey
    data
    text
    <p>I have created a recursive function, and what i need is to get the parent category description and term_id of that product.</p> <pre><code>function desc_pro($parent) { $term = get_term_by('parent', $parent, 'product_cat'); $description = $term-&gt;description; while($description == null) { $desc = desc_pro($term-&gt;parent); return $desc; } return $description; } </code></pre> <p>Now when i run this code, i get the correct description. But if i remove any of the return then it will not work. It shows blank. (This is okay? I think the code is wrong?)</p> <p>Second: I need term_id and when i create the array, it send all the sub category ids as well. Which is wrong. I need just that id which has the description. </p> <p>I think the code is wrong? Or there is any other problem?</p> <p>This is the array with me: (what i send is the parent category from my php page. So i call function get_desc(48);)</p> <p>It give me first object, now i have to test is description available or not? If yes then stop and return description and it's term_id. If it is not available then grab parent id and check again. So this continues, until description is found.</p> <pre><code>stdClass Object ( [term_id] =&gt; 48 [name] =&gt; Cereal [slug] =&gt; cereal [term_group] =&gt; 0 [term_taxonomy_id] =&gt; 49 [taxonomy] =&gt; product_cat [description] =&gt; [parent] =&gt; 46 [count] =&gt; 0 ) stdClass Object ( [term_id] =&gt; 46 [name] =&gt; Grocery Store A [slug] =&gt; grocery-store-a [term_group] =&gt; 0 [term_taxonomy_id] =&gt; 47 [taxonomy] =&gt; product_cat [description] =&gt; FDIC, 17th Street Northwest, Washington, DC [parent] =&gt; 45 [count] =&gt; 0 ) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload