DidouS

dump termmeta fieldnames for a termid

Jun 9th, 2020
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.59 KB | None | 0 0
  1. //
  2. //Dump termmeta fieldnames to the browser
  3. add_action( 'init' , function() {
  4.  
  5.     var_dump( get_termmeta_for_term_id( 41 ));
  6.  
  7. } , 20, 1 );
  8.  
  9. /**
  10.  * get an array of termmeta fieldnames that actually exist on a termid
  11.  * @param  [type] $termid [description]
  12.  * @return [type]         [description]
  13.  */
  14. function get_termmeta_for_term_id( $termid ) {
  15.  
  16.     global $wpdb;
  17.  
  18.     $result = $wpdb->get_results( "SELECT meta_key FROM {$wpdb->prefix}termmeta where term_id = {$termid};" , OBJECT );
  19.  
  20.     $result = array_map( function( $item ) { return $item->meta_key; } , $result );
  21.  
  22.     return $result;
  23.  
  24. }
Add Comment
Please, Sign In to add comment