Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function your_callback_to_return_content(){
- $cat = $_POST['category'];
- $args = array(
- 'category_name'=> $cat,
- 'posts_per_page' => -1
- );
- $slide = 0;
- $ajax_content = '';
- $my_post = new WP_Query($args);
- if($my_post->have_posts()) :
- $ajax_content .= '<div id="#whitepapersshow">';
- while ( $my_post->have_posts() ) :
- $my_post->the_post();
- $ajax_content .= '<h2><a href="'.get_the_permalink().'">'.get_the_title().'</a></h2>';
- endwhile;
- $ajax_content .= '</div>';
- endif;
- echo $ajax_content;
- die;
- }
- add_action('wp_ajax_my_action', 'your_callback_to_return_content');
- add_action('wp_ajax_nopriv_my_action', 'your_callback_to_return_content');
- // enqueue our ajax script file and passing ajaxurl value
- function my_ajax_load_scripts() {
- // get our custom-script.js
- wp_enqueue_script('my-custom-script', get_template_directory_uri() . '/js/custom-script.js');
- // globalize admin-ajax.php url for ajax processing page
- wp_localize_script('my-custom-script', 'my_wp', array(
- 'ajaxurl' => admin_url('admin-ajax.php')
- )
- );
- }
- add_action('wp_enqueue_scripts', 'my_ajax_load_scripts');
- ?>
Advertisement
Add Comment
Please, Sign In to add comment