You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fisrt thing you need to get all categories, use : $cats = get_categories();
Then loop in the categories to get all categories, will need that to get ID of all categories. use:
foreach ($cats as $cat) { $term_id = $cat->term_id; } }
This code will retrive all the ID of each category, then will use the Tax-Meta-class To output the field content,
The final code will be like This:
foreach ($cats as $cat) {
// get $term_id
$term_id = $cat->term_id;
// use the tax_meta-class, use get_term_meta() instand of get_tax_meta()
$saved_data = get_term_meta($term_id,'text_field_id');
// loop in the $saved_data variable
foreach ($saved_data as $saved_d) {
echo $saved_d . '</br>';
}
}
}`
This will display the custom field content for every category.
I hope that will help you.
The documentation at https://en.bainternet.info/wordpress-taxonomies-extra-fields-the-easy-way/ is incorrect. It refers to using
get_tax_meta
to retrieve saved data. Since the update to use the taxmeta table,get_term_meta($term_id, $field_id)
is the correct function to use.The text was updated successfully, but these errors were encountered: