MySQL query for taxonomy-meta

Try select t.name, t.slug, tm.meta_key, tm.meta_value from wp_term_taxonomy AS tt inner join wp_terms AS t ON tt.term_id = t.term_id inner join wp_termmeta AS tm ON t.term_id = tm.term_id where tt.taxonomy = ‘census-tract’ order by t.name

How to display taxonomy term custom meta (using wp_get_object_terms?)?

If those extra fields are saved on Edit User page you should get them with get_user_meta function: $social_twitter_handle = get_user_meta( $curauth->ID, ‘firm_social_twitter_handle’, true ); If those extra fields are attached to each term you can use get_term_meta function: $firm_terms = wp_get_object_terms( $curauth->ID, ‘firm’ ); if ( ! empty( $firm_terms ) ) { if ( ! … Read more

How to relate a user object to taxonomy term?

The function wp_set_object_terms relates to objects (posts, page, etc). You better use usermeta – update_usermeta. E.g update_usermeta( $user_id, ‘company’, $company_id ); WordPress is built by two major database tables (wp_posts and wp_users) and two (meta tables wp_postmeta and wp_usermeta). It seems that the term tables (wp_terms and others) relates to wp_posts. I dealing with the … Read more

Dynamically set taxonomy term and show admin notice on post save

Okay, so just in case anyone needs help on the same thing I did… here is my solution. Instead of a php/wordpress solution, I used javascript. Id love to see the php/wordpress solution if someone wants to post it. <?php // Admin Custom JS add_action(‘admin_head’, ‘admin_custom_js’); function admin_custom_js() { ?> <script> // update date (month) … Read more

How add default term meta to prevent an error?

You don’t, or at least not in the way you expect. If the code in the question worked as expected, it would still be committing a mortal performance sin, database writes on the frontend. So lets take the relevant code: $cat_id = $_GET[‘tag_ID’]; if (metadata_exists(‘term’, $cat_id, ‘cat_settings’ )) { $catSettings = get_term_meta($cat_id, ‘cat_settings’, false); } … Read more

wp_insert_term() doesnt insert a term

Thanks to Milo who asked an important question: Where is this code? I put it below where ive have registered the taxonomy and then it worked: function register_taxonomy() { $labels = array(…); $args = array(…); register_taxonomy( ‘ncategory’, null, $args ); $parent_term = term_exists( ‘Gender’, ‘ncategory’ ); // array is returned if taxonomy is given $parent_term_id … Read more

Create a pre-filtered version of the Media Library

Thanks to Milo for the pointer. I’m going to have to work on my application, but the main point is this filters the media library as required. function only_licensed_images($query){ global $pagenow; if( ! in_array( $pagenow, array( ‘upload.php’, ‘admin-ajax.php’ ) ) ) return; $query->set( ‘attachment_category’, ‘Licensed Stock Images’ ); } add_action(‘pre_get_posts’,’only_licensed_images’);