Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //php
- function ajax_posts_from_cats() {
- // $ids = isset( $_POST['ids'] );
- //update_post_meta( $post_id, 'select_post_cats', $ids );
- if ( !empty( $_POST['ids'] ) ) {
- $posts_loop = get_posts( [
- 'post_type' => 'question',
- 'post_status' => 'publish',
- 'category' => intval($_POST['ids'],),
- ] );
- }
- echo wp_json_encode( $posts_loop );
- exit();
- }
- //JS
- var post_ids = [];
- $(".random_question_selected_categories:checkbox:checked").each(function (i) {
- post_ids[i] = $(this).val();
- });
- var data = {
- action: "select_posts",
- ids: post_ids,
- };
- jQuery.post(ajax_url, data, function (response) {
- console.log(response);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement