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

Enhancement: Meta Boxes for Categories and Taxonomies #53

Closed
patrickf0 opened this issue Jan 14, 2014 · 12 comments
Closed

Enhancement: Meta Boxes for Categories and Taxonomies #53

patrickf0 opened this issue Jan 14, 2014 · 12 comments

Comments

@patrickf0
Copy link

Hi there,

maybe this is an idea for an enhancement to add some meta boxes/ custom fields to a category oder custom taxonomy?

@michaeluno
Copy link
Owner

I quite don't get what you mean by category order custom taxonomy. Do you mean in the edit-tags.php page?

@patrickf0
Copy link
Author

Yes.

@michaeluno
Copy link
Owner

I personally have never had a need to place a meta box in that page.

Can you describe how it would be useful? Also a picture would be helpful that shows how it should look like.

@patrickf0
Copy link
Author

Well I´m working on a project currently and they want to add some icons to each category. I can add an icon via CSS with the ID of the category or slug, but it would be nice if they can adjust this icon by themselves when there is an update of the page for example or the icon.

@michaeluno
Copy link
Owner

It doesn't have to be a meta box, does it, then?

@patrickf0
Copy link
Author

What would be the alternative instead of an image upload field?

@michaeluno
Copy link
Owner

I don't understand the question. Instead of a meta box, not an image upload field, right? Just regular input fields would work.

To be clear, you should post an image that shows how it should look like.

@patrickf0
Copy link
Author

Youre right a meta box is not necessary, a simple upload field, or other fields (like within a meta Box) will suffice.

bildschirmfoto 2014-01-14 um 17 42 30

@michaeluno
Copy link
Owner

Okay. Let me see if I can add that functionality.

In the meantime, how should the framework save the data? Should it add a column in the term_taxonomy table? I guess not, because it's hard to restore the initial state once a column is added.

So I guess storing the data in the options table would be realistic. In that case, the naming of the option keys and the option structure needs to be carefully decided.

Imagine when you retrieve the saved data, and which one would you prefer? Or tell me if there is a better way.

$iTermID = 12;
$sFieldID = 'category_image';
$aData = get_option( "MyTaxonomyFormClassName_{$iTermID}" );
$the_value = $aData[ $sFieldID ];

Or

$iTermID = 12;
$sFieldID = 'category_image';
$aData = get_option( 'MyTaxonomyFormClassName' );
$the_value = $aData[ $iTermID ][ $sFieldID ];

@patrickf0
Copy link
Author

Storing the data in the option table is not quite intuitive, but as wordpress does not support such term meta functionality the only other way is to to add a new table to the database named termmeta similar to postmeta.

But I´d be satisfied with your second solution.

@michaeluno
Copy link
Owner

The branch now includes this feature: https://github.com/michaeluno/admin-page-framework/tree/v3/fields_in_taxonomy_page

How to Use

  1. Define your class extending AdminPageFramework_TaxonomyField including the setUp() method. And add fields with the addSettingFields() method.
  2. Instantiate the class with the following parameters.
    1. taxonomy slug
    2. ( optional ) option key - by default the class name is applied
    3. ( optional ) capability - default: manage_options
    4. ( optional ) text domain - default: admin-page-framework

e.g.

new APF_TaxonomyField( 'apf_sample_taxonomy' );

When retrieving the saved options, do like the following:

$iTermID = 8;   // you need to determine your term id 
$sFieldID = 'your_field_id';
$aOptions = get_option( 'APF_TaxonomyField' );  // the key is just an example, you should set your own key here
$vValue = isset( $aOptions[ $iTermID ][ $sFieldID ] ) ? $aOptions[ $iTermID ][ $sFieldID ] : null;

The example of instantiating the extended class is included in the demo plugin. ( admin-page-framework-demo.php ) The example of extending the framework class is written in ./example/APF_TaxonomyField.php.

taxonomy_fields

@michaeluno
Copy link
Owner

It's been functioning well so I'm closing the topic.

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

No branches or pull requests

2 participants