Posted By

thefrosty on 10/22/10


Tagged

php wordpress json


Versions (?)

json_encode()


 / Published in: PHP
 

I can\\'t this function to fire WordPress shortcodes or getmetadata:\r\n\r\nProblem 1. In the shortcode, if I remove \\'.$item.\\' and replace with it\\'s regular value that the post_meta holds (hard code it) this works just fine. Also the same with the $numb variable.\r\n\r\nHave any ideas why these variable aren\\'t working before they\\'re encoded?

  1. function discount() {
  2. global $post;
  3.  
  4. $item = get_post_meta( $post->ID, 'item_number_discount', true );
  5. $numb = str_replace( 'theme-', '', $item );
  6.  
  7. $arr = array();
  8. $entry['code'] = "success";
  9. $entry['link'] = '<a class="purchase discount" href="javascript:{}" onclick="document.getElementById(\'cartButtonForm_'. $numb .'\').submit(); return false;">Purchase discount</a>';
  10. $entry['form'] = do_shortcode( '[cart-button item="'.$item.'" showprice="no" ]' );
  11.  
  12. $arr[] = $entry;
  13. header("Content-Type: application/json");
  14. echo json_encode($arr);
  15. exit();
  16.  
  17. }
  18. add_action( 'wp_ajax_add_discount', 'discount' ); //hook to ajax action
  19. add_action( 'wp_ajax_nopriv_add_discount', 'discount' ); //hook to ajax action

Report this snippet  

You need to login to post a comment.