[wp-trac] [WordPress Trac] #17336: Can't use get_the_terms() within a function that hooks into publish_post

WordPress Trac wp-trac at lists.automattic.com
Fri May 6 00:19:25 UTC 2011


#17336: Can't use get_the_terms() within a function that hooks into publish_post
--------------------------+-----------------------------
 Reporter:  defunctlife   |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Taxonomy      |    Version:  3.1
 Severity:  normal        |   Keywords:
--------------------------+-----------------------------
 I've tried everything, but get_the_terms() always returns false. When
 using a similar function on the actual single.php page it works fine. I
 have confirmed the correct post id's are being returned within the
 dashboard. I have also confirmed that indeed these posts have a taxonomy
 item of myshift_title from within the dashboard. I tried
 wp_get_object_terms() but it returns an empty array.

 From what I can tell I just can access a post's taxonomy, and I would
 really like to.

 From my functions.php

 {{{
 function shift_add_progress_report_notification($post_ID) {

         /* Register the taxonomy as we don't seem to have access to it
 here */
         register_taxonomy('myshift_title', array('myshift', 'post'),
 array('label' => 'My Shift Title', 'rewrite' => false, 'query_var' =>
 true));

         $terms = get_the_terms( $post_ID, 'myshift_title');

         ob_start();
         var_dump($terms);
         $a = ob_get_contents();
         ob_end_clean();

         mail('xxxxxxx', 'Progress Report', $a . ' POST ID: ' . $post_ID);
 }
 add_action( 'publish_post', 'shift_add_progress_report_notification', 10,
 1);
 }}}

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/17336>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list