Posted By

thefrosty on 01/05/11


Tagged

wordpress taxonomy


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

baires


Manage Custom $taxonomy column meta


 / Published in: PHP
 

It's working now. Just having issue with it applying to all columns. Need to keep checking. (IE. have to tax's for testing, only one has the additional meta info attached, but they are both showing in the column as having the address as "active" (using same addy for both) will play more ).

  1. /**
  2.  * Lets manage the new column
  3.  *
  4.  * @ref http://wordpress.org/support/topic/custom-post-type-admin-ui-with-custom-taxonomies
  5.  * @ref http://wordpress.org/support/topic/add-id-column-to-custom-taxonomy-admin-display-1
  6.  * @help http://snipplr.com/view/46538/manage-custom-taxonomy-column-meta/ (??)
  7.  * @since 0.1.0
  8.  */
  9. function manage_venues_column( $tag, $column_name ) {
  10. global $wpdb, $taxonomy, $post, $post_type;
  11.  
  12. /* get_metadata( $meta_type, $object_id, $meta_key = '', $single = false ) */
  13.  
  14. $address = get_metadata( 'venues', get_venues_id_by_key( 'address' ), 'address', true );
  15. $city = get_metadata( 'venues', get_venues_id_by_key( 'city' ), 'city', true );
  16. $state = get_metadata( 'venues', get_venues_id_by_key( 'state' ), 'state', true );
  17. $zip = get_metadata( 'venues', get_venues_id_by_key( 'zip' ), 'zip', true );
  18.  
  19. $gmaps = 'http://maps.google.com/maps?q=';
  20. if ( !empty( $address ) )
  21. $gmaps .= urlencode( $address );
  22. if ( !empty( $city ) )
  23. $gmaps .= '+' . urlencode( $city );
  24. if ( !empty( $state ) )
  25. $gmaps .= ',+' . urlencode( $state );
  26. if ( !empty( $zip ) )
  27. $gmaps .= '+' . urlencode( $zip );
  28.  
  29. $map_script = "<script type='text/javascript'>jQuery(document).ready( function() {
  30. jQuery('th#maps.manage-column.column-maps').css({ textAlign: 'center', width: '10%' });
  31. jQuery('td.maps.column-maps').css({ textAlign: 'center', width: '10%' });
  32. });</script>";
  33.  
  34. $edit_link = get_edit_term_link( $tag->term_id, $taxonomy, $post_type ); //Not correct, need old query_var_something....
  35.  
  36. switch( $column_name ) {
  37. case 'maps' :
  38. if ( !empty( $address ) ) {
  39. echo $map_script . '<a href="'.$gmaps.'" target="_blank" style="color:green"><strong>&radic;</strong></a>';
  40. } else {
  41. echo $map_script . '<a class="nomap" href="' . $edit_link . '" style="color:red"><strong>&chi;</strong></a>' . var_dump( get_venues_id_by_key( 'address' ) );
  42. }
  43. break;
  44. }
  45.  
  46. }
  47.  
  48. /**
  49.  * Try to get the ID by way of $wpdb
  50.  *
  51.  * @ref http://wpseek.com/blog/2010/how-to-get-the-meta-id-by-meta-key/80/
  52.  * @since 0.1.0
  53.  */
  54. function get_venues_id_by_key( $meta_key ) {
  55. global $wpdb;
  56.  
  57. $venue = $wpdb->get_var( $wpdb->prepare( "SELECT venues_id FROM $wpdb->venuesmeta WHERE meta_key = %s", $meta_key ) );
  58.  
  59. if ( $venue != '' )
  60. return (int)$venue;
  61.  
  62. return false;
  63. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: thefrosty on January 5, 2011

My $address variable is not being recognized.

Posted By: thefrosty on January 5, 2011

Even updated: getmetadata( 'venues', $tag->termid, 'address', true );

Posted By: thefrosty on January 5, 2011

Seems that $tag isn't recognized.

Posted By: thefrosty on January 5, 2011

This doesn't help either:

if ( empty( $tag ) ) $tag = 'venues';

Posted By: thefrosty on January 5, 2011

Thinking because my custom meta is in another table, it's not grabbing it.

Posted By: thefrosty on January 5, 2011

$venues = $wpdb->getresults( "SELECT venuesid FROM $wpdb->venuesmeta WHERE meta_key = address" );

Posted By: thefrosty on January 5, 2011

$address = getmetadata( 'venues', $venues->venueid, 'address', true );

Posted By: thefrosty on January 5, 2011

BTW, there ARE underscores in those comments where some stuff if normal then italic.. (??)

You need to login to post a comment.