0

I'm trying to pass a custom field value into a custom taxamony whenever I publish a post. Everything works fine except the meta value part. I can only pass strings. In the codex it says that wp_set_post_terms takes either string or array, tag or category. But can't I echo a meta value?

     function add_author_taxonomy( $post_id ) {
     global $wpdb;
     if(!wp_is_post_revision($post_ID)) {
         wp_set_post_terms( $post_id, echo get_post_meta($post_id, 'user_submit_customauthor', true) , 'author', true ); 
         }
     }
     add_action('publish_page', 'add_author_taxonomy');
     add_action('publish_post', 'add_author_taxonomy');
0

have you tried building your tag array into a variable and passing that as a parameter to set_post_terms?

 function add_author_taxonomy( $post_id ) {
     global $wpdb;
     if(!wp_is_post_revision($post_ID)) {
         $my_tags = get_post_meta($post_id, 'user_submit_customauthor', true); 
         wp_set_post_terms( $post_id, $my_tags, 'author', true ); 
         }
     }
     add_action('publish_page', 'add_author_taxonomy');
     add_action('publish_post', 'add_author_taxonomy')

;

  • That did work, but adding that variable conflicted with another plugin. The action no longer trigger when I submit my posts in the front end. It did before, without the extra variable.. strange – Tony Fire Jan 11 '14 at 11:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.