Comments

  1. Al says

    Hello Shiba,

    Great tutorial.

    Is that anyway we sort taxonomy term by meta_value? or can I retrieve taxonomy terms data using get_terms where $args = array (‘orderby’ => $meta_key or $meta_value)?

    Thanks very much,

    -Al
    Select term_id from taxonomy_term table

  2. Karen says

    Hi Shiba,

    I’m afraid I’ve never written a WordPress plugin, but if I understand your post correctly, it sounds like the setup for exactly what I hope to do: Beyond “Name,” “Slug,” and “Description,” there are some additional custom properties that I’d like to be able to specify for the tags on my (customized, self-hosted) WordPress site. So I’d like to add some custom input fields to the “Add New Tag” interface.

    In the hopes that your sample code would make just such a new custom field, I familiarized myself with the basic structure of a plugin (including registering activation function and then calling the admin-init function), and I built your sample code into what I think should be a working plugin. (I even retained “shiba_term” as the value of $type–figuring I could start customize the names after I got it working). Installing and activating it doesn’t create a new field, though–I’m sure because I’m doing something wrong and don’t know it!

    I’m certain I’m being a pest by replying to your lovely tutorial with the ultimate newbie question, but would much appreciate any guidance you can offer–even so much as pointing me to a good source where I can pick up the basics of writing/implementing plugins?

    Please do email me if you can spare the time and patience, and I can send you what I put together (I tried to paste it in this comment but I see that doesn’t go through).

    Many thanks!!! (And what beautiful artwork throughout your site–really counteracts the stress I usually feel when grappling with code!)

    :)

    • ShibaShake says

      I think there are some plugins that provide some higher level support for adding metadata to custom taxonomies.
      http://wordpress.org/plugins/taxonomy-metadata/

      I haven’t used the plugin so I don’t have any details, but it (or others like it) might be a good starting point if you want to write your own plugin. Or you can just use that as a base, and built on top of it.

  3. Lorenzo says

    hello, is a long time that I’m trying to change this plugin “WP user frontend” to add the Taxonomy form the front end form. My template already integrates Taxonomy so the only thing needed is just to upload data Taxonomy in areas already created from the template.
    In this page http://tareq.wedevs.com/2012/04/how-to-extend-wp-user-frontend
    the author of the plugin explains how to make changes in particular I thought the interesting part would be this:

    :lots of code:

    Can we help me???
    thank you very much!!

  4. says

    Hi Folks. This is an awesome tutorial I found a day to late.

    The downside here is creating that new table. In 2.9 we didn’t have any other options, but now in 3.0+ you can accomplish it with a custom post type.

    The code in this pastebin is an EXAMPLE and hasn’t been thoroughly tested.

    http://pastebin.com/zYy6PePz

    Feedback is appreciated.

  5. Manny Fleurmond says

    Hi! Thanks for the code examples, but I was wondering how you can set it so that the metabox only appears under certain taxonomies and not all of them?

    • ShibaShake says

      Instead of using the edit_tag_form_fields action hook, use the specific taxonomy action hook instead.

      add_action ( $my_taxonomy . '_edit_form_fields', 'tag_input_metabox', 10, 2 );
      function tag_input_metabox($tag, $taxonomy) {
      ...
      }
      
  6. says

    Hey Shiba ! Great work.

    Can you let me know how can we achieve the same thing with category ??

    Also, it could have been great if you have posted the screenshot of tags meta in dashboard.

    Thanks
    Jaz

    • ShibaShake says

      Can you let me know how can we achieve the same thing with category ??

      Just use the category term_id.

      Also, it could have been great if you have posted the screenshot of tags meta in dashboard.

      Check out Dashboard Widgets API.

  7. says

    Great information! Now, please excuse the newbishness… I want to use this method in my own theme and have some questions. I can see that shiba-meta.php and shiba-theme-metabox.php are not “drag-n-drop” ready. Can you comment on what terms and variables used in those files have external dependencies? The use of the term ‘theme’ through out the files has me a bit confused. For example:
    update_post_meta( $post_id, ‘theme’, $theme_id);
    ‘theme’ is used as $meta_key but I can’t seem to find where that key was defined. Also, can you explain your use of global $shiba_theme?
    Thank you for the great information, and thank you in advance for your response!

    • ShibaShake says

      ‘theme’ is used as $meta_key but I can’t seem to find where that key was defined.

      ‘theme’ is just the name of the custom field and does not need to be separately defined, e.g. the name ‘new_metadata’ in the example above. Check out get_post_meta and update_post_meta.

      It may be easiest to just follow the tutorial above rather than try to decode the files used in Shiba Theme. Shiba Theme contains a lot of other features and separating out the parts that you need may be more work than starting from a clean slate.

      • says

        I realized (again) why I should NOT try coding late in the evening. I get all cross eyed and make really dumb mistakes. But anyway… I am wondering now where you came up with the action hooks you are using:

        add_action ( ‘edit_tag_form_fields’, ‘tag_widget_metabox’ );
        add_action ( ‘edited_terms’, ‘save_tag_data’ );

        There seems to be no documentation on them in the codex. Also, you suggested I look at the post_meta functions. I don’t understand the reason for that since we are not working with $post meta data, but rather $tag or $term meta data. Even in your example there is no use of get_post_meta(), but rather get_metadata(). And of course there is little documentation on those functions…

        • ShibaShake says

          I am wondering now where you came up with the action hooks you are using

          I usually find the proper hooks by looking at the WordPress source code. For example, if I need to add something to the Media Edit screen, I start by looking at that file and then follow related functions until I find the appropriate hooks.

          I only suggested looking at post_meta because you asked -

          The use of the term ‘theme’ through out the files has me a bit confused. For example:
          update_post_meta( $post_id, ‘theme’, $theme_id);

          I was not sure if you were interested in adding meta-data to posts, terms, or both.

  8. Rafael Dourado says

    You could have used the action ‘edited_shiba_term’ instead of ‘edited_terms’.
    And you could also have used ‘shiba_term_add_form_fields’ and ‘create_shiba_term’ actions to add the new field to Add Taxonomy screen.

  9. says

    How do you add metadata to WordPress sites that are not hosted by me if I can’t add plugins? Can you give specific directions if this is possible?

  10. James Lafferty says

    Nice tutorial… it definitely got me looking around in the right places to get stuff done. I actually wound up needing to call $wpdb->query() from my function to create the table, though, which from the looks of it isn’t fantastic practice. Would you be able to elaborate at all on the drawbacks of using $wpdb->query() rather than dbDelta() here, if that’s not just too insanely geeky. From what I can tell the biggest issue is if I want to modify my schema at some future date, dbDelta() would better position me to handle that.

    • ShibaShake says

      Truthfully, I only used dbDelta because that was used in the WordPress Codex example.

      I looked at the dbDelta function briefly and it seems that it can be used to execute multiple creation and insertion queries. I think the main advantage is that it can be used to modify the structure of existing tables.

      It also does more validation in terms of checking for global tables, etc.

      However, there were also some open tickets on it, and I have had some people reporting plugin bugs that may be the result of dbDelta not working properly on their server setup. What happened when you used dbDelta? What error did it return?

      • James Lafferty says

        Jeez, I feel lame for not replying, and at this point, I can’t remember what error it returned. I’ll see if I can backtrack and figure out what went wrong. Again, love your take on things WP.

        • James Lafferty says

          Having had a second look, it seems like I had an issue with ‘require_once(ABSPATH . ‘wp-admin/includes/upgrade.php’);’ — mostly it was a flow thing, but I was also concerned about potentially doing that include a lot, as I was trying to create the table only if there was term metadata specified elsewhere… A little convoluted as a reply, I know, but the gist of it is that I didn’t have an error, just didn’t want to load upgrade.php all the time.]

          Cheers!

          • James Lafferty says

            Just wanted to let you know that your blog definitely in part inpired me to write my Term Menu Order Plugin (released just today). The other inspiration was that I needed the functionality for a site I was working on.

            The key insight I got from your blog was looking at terms as potentially the same as posts in ways that could be surprising (i.e., the termmeta table you use here inspired me to consider simply adding a menu_order column to the terms table).

            As a point of relevance to this particular thread, dbDelta didn’t work for this either, as it filters out ALTER TABLE queries (looks like it only accepts CREATE TABLE, CREATE DATABASE, INSERT and UPDATE).

          • ShibaShake says

            Hi James,
            Congratulations on your new plugin release and thanks for your comment. I will definitely check your plugin out. I truly enjoy this side of the WP community – the sharing of ideas, code, and encouragement.

            Merry Christmas and Happy Holidays!

  11. Modesty says

    ShibaShake,
    can I paste all of this in to my functions.php or does it have to be a plugin? what would be the final version of the whole code together?

    many tnx

    m

    • ShibaShake says

      I wouldn’t recommend doing this unless you are comfortable with PHP and database operations.

      The code involves creating a table, which means writing to your database and you don’t want to do that unless you totally understand the code and are comfortable with basic database manipulation on your server. Otherwise, you may end up corrupting your database.

      If you want a full example of the code the Shiba Theme, Shiba Background plugin, and Shiba Widgets plugin all use it.
      Table creation is in shiba-meta.php and some examples of update_post_meta and delete_post_meta are in shiba-*-metabox.php.

      Remember to backup your database first just to be safe.

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>