logo
Ask your WordPress questions! Pay money and get answers fast! (more info)

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.

$7
Custom Field Values as Taxonomy Terms

I use bunch of custom fields in a custom post type. However, I need some of the custom field to be used as taxonomy as well. For example,

I have a custom field called Place and A custom taxonomy called States. So the value that user insert into CF State (eg. ohio), also automatically become the term in taxonomy States.

The States taxonomy inserting function should be run in behind automatically. No need to display to the user.

How do I achieve this?

Thanks

house.tc | 05/25/12 at 1:54pm Edit


(3) Possible Answers Submitted...

Note: house.tc felt their question was unanswered, so we granted them a refund.

Note: house.tc requested a refund. They offered this explanation:

"There were only references in my question which I have no time to read it. "

If no one challenges a refund request, then they are automatically granted and proccessed after 48 hours. Admins of this site only review refund requests if someone challenges the request. If you are curious about how we handled previous refund requests, you may read over all refund requests and their challenges.

See a chronological view of answers?

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

  • avatar
    Last edited:
    05/25/12
    2:09pm
    Arnav Joy says:

    you can use following function
    <?php wp_insert_term( $term, $taxonomy, $args = array() ); ?>

    Previous versions of this answer: 05/25/12 at 2:09pm

  • avatar
    Last edited:
    05/25/12
    2:06pm
    Francisco Javier Carazo Gil says:

    You have to do a call to wp_insert_term when you are saving or updating value of custom field.

    • 05/25/12 2:14pm

      Francisco Javier Carazo Gil says:

      You have to use this function at the same time you save your meta with update post meta: http://codex.wordpress.org/Function_Reference/update_post_meta

      If the values has changed, you have to be careful, first check if new value exists with has_term http://codex.wordpress.org/Function_Reference/has_term and later:
      * if exist in the same post: do nothing
      * if not exist: delete the old term with old value and create a new one

    • 05/25/12 2:30pm

      house.tc says:

      The problem is I am using plugin to create those custom meta field. How do I use update_post_meta? Hook in function.php? It would be great if you have some example of the codes. thanks

  • avatar
    Last edited:
    05/25/12
    2:23pm
    John Cotton says:

    Can I ask why you want to do this?

    If you're going to set a taxonomy value, surely the custom field is redundant? (Or vice versa)

    You can query by taxonomy and query taxonomy by post....I can't think of a reason why you want this :)

    • 05/25/12 2:42pm

      house.tc says:

      Well, since there are no plugin to create custom taxonomy input panels (like dropdown, button, etc) ,create custom meta field is much easier with plugin. Besides, there are many fields my post-type, it would be very time consuming to create each taxonomy manually.

      However, taxonomy is easier to categories or sort in the front end. Custom field in the other hand is lack of this advantage.

      I know it sound stupid to do this, but be frankly I am not too familiar with wp, so I couldn't come up a better idea.

    • 05/25/12 2:58pm

      John Cotton says:

      Since you're going to have to write some code somewhere to do what you want, you'll find it much easier to code what you want directly without the custom field plugin....

      Have a look at this:

      http://codex.wordpress.org/Function_Reference/add_meta_box

      It shows you how to code your own meta box. With it, you can add all sorts of user interface to get what you want. Better code....easier for the user....

This question has expired.





Current status of this question: Refunded



Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.