• 23 Comments
    1. 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.

      1:14 pm on March 27th, 2011 Reply
    2. Manny Fleurmond

      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?

      5:27 am on December 14th, 2010 Reply
      • 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) {
        ...
        }
        9:41 am on December 14th, 2010 Reply
    3. 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

      5:38 am on November 10th, 2010 Reply
      • 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.

        8:28 am on November 10th, 2010 Reply
    4. 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!

      7:46 pm on November 9th, 2010 Reply
      • ‘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.

        8:14 am on November 10th, 2010 Reply
        • 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…

          5:50 pm on November 13th, 2010 Reply
          • 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:42 am on November 15th, 2010 Reply
    5. Perfect! This is great to find as I had no idea that this was even possible. Thanks for posting.

      2:05 am on September 25th, 2010 Reply
    6. Rafael Dourado

      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.

      8:01 am on August 25th, 2010 Reply
    7. 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?

      9:27 am on August 12th, 2010 Reply
      • This will only work for self-hosted WordPress sites.

        9:47 am on August 12th, 2010 Reply
    8. James Lafferty

      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.

      9:26 am on August 3rd, 2010 Reply
      • 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?

        10:58 am on August 4th, 2010 Reply
        • James Lafferty

          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.

          5:55 pm on December 14th, 2010 Reply
          • James Lafferty

            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!

            9:38 am on December 15th, 2010 Reply
            • Thanks for getting back to me James. This definitely helps. :D

              7:59 am on December 16th, 2010
            • James Lafferty

              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).

              1:29 am on December 17th, 2010
            • 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!

              1:40 pm on December 18th, 2010
    9. Modesty

      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

      6:31 am on July 31st, 2010 Reply
      • 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.

        8:32 pm on August 1st, 2010 Reply
    10. Great tutorial! This is exactly what I was looking for.

      Thank you!

      11:27 pm on July 13th, 2010 Reply

    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> <pre lang="" line="" escaped="" highlight="">

    search button search button
    rss