Advertisement
ikamal

post json

Jun 17th, 2020
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. //php
  2.  
  3. function ajax_posts_from_cats() {
  4. // $ids = isset( $_POST['ids'] );
  5. //update_post_meta( $post_id, 'select_post_cats', $ids );
  6. if ( !empty( $_POST['ids'] ) ) {
  7. $posts_loop = get_posts( [
  8. 'post_type' => 'question',
  9. 'post_status' => 'publish',
  10. 'category' => intval($_POST['ids'],),
  11. ] );
  12. }
  13.  
  14. echo wp_json_encode( $posts_loop );
  15. exit();
  16. }
  17.  
  18. //JS
  19.  
  20. var post_ids = [];
  21. $(".random_question_selected_categories:checkbox:checked").each(function (i) {
  22. post_ids[i] = $(this).val();
  23. });
  24.  
  25. var data = {
  26. action: "select_posts",
  27. ids: post_ids,
  28. };
  29.  
  30. jQuery.post(ajax_url, data, function (response) {
  31. console.log(response);
  32. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement