Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting Saved Data #132

Open
jeremylind opened this issue Sep 20, 2016 · 2 comments
Open

Getting Saved Data #132

jeremylind opened this issue Sep 20, 2016 · 2 comments

Comments

@jeremylind
Copy link

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.

@JQOz
Copy link

JQOz commented Sep 13, 2017

Hi ,

if i paste the vode bwlow in archive.php, i got nothing.

<?php
$saved_data = get_term_meta($term_id,'text_field_id');
echo $saved_data;
?>

Where sholud i use the code? In which file?

@OussamaKhoubran
Copy link

OussamaKhoubran commented May 18, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants