michaeluno / admin-page-framework

Facilitates WordPress plugin and theme development.
http://admin-page-framework.michaeluno.jp/
Other
337 stars 71 forks source link

Get taxonomy term custom fields value #213

Closed vladkucherov closed 9 years ago

vladkucherov commented 9 years ago

Hi,

I searched over your framework, And I couldn't find anywhere a method to fetch the custom fields I created for taxonomy term.

I have a taxonomy game and I added it this field:

class Fields_Settings_TaxonomyField extends AdminPageFramework_TaxonomyField {

    public function setUp() {
        $this->addSettingFields(
            array(
                'field_id'      => 'url',
                'type'          => 'text',
                'title'         => __( 'Destination URL', 'topfive' ),
            )
        );
    }

}

The field is working and saving like it should, but how I can get the data stored? I couldn't find any method, I didn't find anything in an example, and it looks like you are not using any filter to add anything the a term from the custom fields.

from your code:

    public function _replyToDetermineToLoad($oScreen) {
        if (!$this->_isInThePage()) {
            return;
        }
        $this->_setUp();
        $this->oUtil->addAndDoAction($this, "set_up_{$this->oProp->sClassName}", $this);
        $this->oProp->_bSetupLoaded = true;
        add_action('current_screen', array($this, '_replyToRegisterFormElements'), 20);
        foreach ($this->oProp->aTaxonomySlugs as $__sTaxonomySlug) {
            add_action("created_{$__sTaxonomySlug}", array($this, '_replyToValidateOptions'), 10, 2);
            add_action("edited_{$__sTaxonomySlug}", array($this, '_replyToValidateOptions'), 10, 2);
            add_action("{$__sTaxonomySlug}_add_form_fields", array($this, '_replyToPrintFieldsWOTableRows'));
            add_action("{$__sTaxonomySlug}_edit_form_fields", array($this, '_replyToPrintFieldsWithTableRows'));
            add_filter("manage_edit-{$__sTaxonomySlug}_columns", array($this, '_replyToManageColumns'), 10, 1);
            add_filter("manage_edit-{$__sTaxonomySlug}_sortable_columns", array($this, '_replyToSetSortableColumns'));
            add_action("manage_{$__sTaxonomySlug}_custom_column", array($this, '_replyToPrintColumnCell'), 10, 3);
        }
    }

Everything looks to be related to the admin area - which is great. But what if I need the data stored from within a look using get_term() WP function?

Please advice

(Sorry for lots of questions, things are not quite clear to me)

michaeluno commented 9 years ago

Hi,

$aOptions = get_option( 'YourClassNameHere' ); 

(reference: https://github.com/michaeluno/admin-page-framework/issues/53#issuecomment-32704192)


Don't worry about asking lots of questions. They should help other users. Just make sure they are clear.

vladkucherov commented 9 years ago

@michaeluno Hi,

Don't you think this is something that should work similar to the posts? I mean maybe you should add filter to the term object to add additional attributes by the custom fields?

$term->custom_var

instead of:

$custom_vars[$term->term_id]['custom_var']

What do you think? This should be something easy to do I think. Want me to add this?

michaeluno commented 9 years ago

I mean maybe you should add filter to the term object to add additional attributes by the custom fields?

It is impossible to tell when and where the site of the user uses a taxonomy. The framework is not designed to be loaded in every single page load, after all.

What do you think? This should be something easy to do I think. Want me to add this?

I don't see it is necessary. However, if you really think it is useful, you may show how you do it by requesting a pull.

Closing the topic as the initially addressed problem seems to be resolved.