showing results for - "ajax in wordpress"
Facundo
26 Mar 2019
1add_action('wp_ajax_myfilter', 'misha_filter_function'); // wp_ajax_{ACTION HERE} 
2add_action('wp_ajax_nopriv_myfilter', 'misha_filter_function');
3 
4function misha_filter_function(){
5	$args = array(
6		'orderby' => 'date', // we will sort posts by date
7		'order'	=> $_POST['date'] // ASC or DESC
8	);
9 
10	// for taxonomies / categories
11	if( isset( $_POST['categoryfilter'] ) )
12		$args['tax_query'] = array(
13			array(
14				'taxonomy' => 'category',
15				'field' => 'id',
16				'terms' => $_POST['categoryfilter']
17			)
18		);
19 
20	// create $args['meta_query'] array if one of the following fields is filled
21	if( isset( $_POST['price_min'] ) && $_POST['price_min'] || isset( $_POST['price_max'] ) && $_POST['price_max'] || isset( $_POST['featured_image'] ) && $_POST['featured_image'] == 'on' )
22		$args['meta_query'] = array( 'relation'=>'AND' ); // AND means that all conditions of meta_query should be true
23 
24	// if both minimum price and maximum price are specified we will use BETWEEN comparison
25	if( isset( $_POST['price_min'] ) && $_POST['price_min'] && isset( $_POST['price_max'] ) && $_POST['price_max'] ) {
26		$args['meta_query'][] = array(
27			'key' => '_price',
28			'value' => array( $_POST['price_min'], $_POST['price_max'] ),
29			'type' => 'numeric',
30			'compare' => 'between'
31		);
32	} else {
33		// if only min price is set
34		if( isset( $_POST['price_min'] ) && $_POST['price_min'] )
35			$args['meta_query'][] = array(
36				'key' => '_price',
37				'value' => $_POST['price_min'],
38				'type' => 'numeric',
39				'compare' => '>'
40			);
41 
42		// if only max price is set
43		if( isset( $_POST['price_max'] ) && $_POST['price_max'] )
44			$args['meta_query'][] = array(
45				'key' => '_price',
46				'value' => $_POST['price_max'],
47				'type' => 'numeric',
48				'compare' => '<'
49			);
50	}
51 
52 
53	// if post thumbnail is set
54	if( isset( $_POST['featured_image'] ) && $_POST['featured_image'] == 'on' )
55		$args['meta_query'][] = array(
56			'key' => '_thumbnail_id',
57			'compare' => 'EXISTS'
58		);
59	// if you want to use multiple checkboxed, just duplicate the above 5 lines for each checkbox
60 
61	$query = new WP_Query( $args );
62 
63	if( $query->have_posts() ) :
64		while( $query->have_posts() ): $query->the_post();
65			echo '<h2>' . $query->post->post_title . '</h2>';
66		endwhile;
67		wp_reset_postdata();
68	else :
69		echo 'No posts found';
70	endif;
71 
72	the ( ) ;
73}
Alan
16 May 2018
1function my_enqueue() {
2      wp_enqueue_script( 'ajax-script', get_template_directory_uri() . '/js/my-ajax-script.js', array('jquery') );
3      wp_localize_script( 'ajax-script', 'my_ajax_object', array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) );
4 }
5 add_action( 'wp_enqueue_scripts', 'my_enqueue' );
6
7//After you can do in js
8jQuery.ajax({
9    type: "post",
10    dataType: "json",
11    url: my_ajax_object.ajax_url,
12    data: formData,
13    success: function(msg){
14        console.log(msg);
15    }
16});
Jan
01 May 2016
1jQuery(document).ready( function() {
2
3   jQuery(".user_vote").click( function(e) {
4      e.preventDefault(); 
5      post_id = jQuery(this).attr("data-post_id")
6      nonce = jQuery(this).attr("data-nonce")
7
8      jQuery.ajax({
9         type : "post",
10         dataType : "json",
11         url : myAjax.ajaxurl,
12         data : {action: "my_user_vote", post_id : post_id, nonce: nonce},
13         success: function(response) {
14            if(response.type == "success") {
15               jQuery("#vote_counter").html(response.vote_count)
16            }
17            else {
18               alert("Your vote could not be added")
19            }
20         }
21      })   
22
23   })
24
25})
Martina
28 Jan 2016
1echo '<button id="ZapisPrace">Save</button>
2<script>
3jQuery("#ZapisPrace").click(function($){
4    var data={
5        action: "addToDB",
6        info: "nomz"
7    };
8    jQuery.post(ajaxurl,data,function(response){
9    alert("Response was "+ response);
10    });
11});
12</script>';
13add_action('wp_ajax_addToDB','pridajDoDB');
14function pridajDoDB(){
15    echo '<script>console.log("AAA")</script>';
16    wp_die();
17}
queries leading to this page
wordpress ajax run php functionajax filter with visual wordpresswordpress ajax in pluginuse ajax in plugin wordpresswordpress plugin ajax without add actionwordpress ajax examplehow to add ajax in wordpresscreate ajax api wordpresshow to use ajax wordpresshow to handle ajax in wordpresswordpress ajax post filterwordpress api filter ajax callhow i call ajax for wordpresswordpress ajax filter and pagnationwordpress add ajaxwordpress ajax includeways to use ajax in wordpresshow to ajax call wordpresswordpress ajax action urlcustom wordpress filteration using for ajaxajax button wordpress 24 ajax wordpresswordpress ajax linkcreate ajax function in wordpresswordpress ajax call php filewordpress custom ajax callajax jquery wordpresswordpress ajax request in 22javascript 22 instead of jquerylink to ajax request wordpresswordpress ajax pluginuse ajax to do a mysql query in wordpressajax filtering wordpresswordpress filter items ajaxajax with jquery and wordpresscreate post filter htmlwordpress ajax jquerywordpress ajax plugin examplefilter in wordpress using ajaxajaxurl in wordpresswordpress ajax request exampleajax request php function in wordpress pluginmake ajax call in wordpresswp ajax in wordpresswordpress ajax filter cptwordpress ajax how tohow to use jquery ajax in wordpressajax jquery for wordpresswordpress ajax post to websitehow to use ajax in wordpressuse ajax with wordpress widgetwordpress do wp ajax callbest way to call ajax wordpresssimple wordpress ajax exampleajax calls on wordpresswordpress with ajaxcall wordpress function ajaxajax call wordpress in jquerywordpress ajax call php functionwordpress plugin ajaxj filterajax wordpress plugin examplewp ajax wordpress documentation call wordpress filter ajaxwordpress ajax for filterjquery wordpress ajaxwordpress ajax sitewordpress how to do an ajax call to wp ajaxwp ajax filter for post titlewordpress ajax handleradmin ajax phpwp ajax requesttrigger ajax command wordpressis ajax in wordpressajax javascript wordpresswordpress filter posts with ajaxwordpress filter posts by category ajaxcall filter on ajax wordpresswordpress ajax demohow ajax works on wordpressways to do ajax in wordpresswordpress ajax post filter pluginhow to generate a an ajax call in wordpresswordpress ajax api callhow to add ajax call in wordpressajax wordpress simple examplewordpress ajax filter posts by category tutorialwp ajax filterswordpress add wp ajax actionhow to filter wordpress pages using ajaxwordpress ajax phpwordpress ajax call in function phpajax in wordpresswordpress ajax trigger codeajax in wordpress pluginwordpress function ajax actionajax wordpress tutorialwordpress add wp ajax add ajax wordpressadd ajax inline wordpresscall ajax on button click wordpressadd ajax in wordpress function phpwordpress ajax stopapply filter on ajax result wordspresswordpress ajax functionajax step by step filter wordpressadd ajax in wordpressajax wordpress wordpress ajax request functionwordpress ajax in wordpresswordpress ajax filters for custom taxonomyon ajax call filter wordpressajax request on wordpressajax function wordpressajax url in wordpresshow to send ajax request in wordpressajax call to wordpress functionajax request jquery wordpresswordpress handle ajaxajax in wordpress examplewordpress function ajax action performusing ajax in wordpressajax filter wordpressfunction wordpress ajax wordpress ajax callcategory filter wordpress code ajaxhow to filter page in wordpress use ajaxajax call in wordpressajax filter in wordpress hookwordpress ajax filterwordpress request ajaxajax call wordpress functionhow to call simple ajax in wordpressajax and wordpresshow to call ajax in wordpresswordpress ajax request in javascriptwordpress ajax callsajax example wordpressajax call wordpresswordpress make ajax requestwordpress ajax get requestajax taxonomy filter wordpressworking with wordpress ajaxajax for wordpresswordpress ajaxrequestusing ajax in wordpress pluginhow to use get ajax method in wordpresswordpress custom ajaxfilter post by category wordpress ajax codewrite ajax in wordpressajax in worpresswordpress add ajax callbackwordpress ajax filter queryhow to trigger ajax function with button click in wordpressrun ajax on wordpressajax request in wordpresshow to make an ajax call in wordpressajax callback in wordpresswordpres ajax pageajax call in wordpress programmaticallyusing ajax with wordpresswordpress ajax filtersajax wpquery filterhow to give function php in ajax in wordpresswp plugin ajax requestajax post filterwordpress jquery ajax example tutorialuse ajax in wordpress wordpress use ajax in pluginhow to use ajax for wordpress websitewordpress ajaxurlwordpress blocks ajax filter pluginfilter ajax wordpress pluginajax wordpress exampleajax filter plugin wordpresswordpress ajax exampewordpress blocks ajax filterjquery ajax wordpresscall ajax in wordpressajax request wordpresswordpress using ajaxwordpress calling ajaxwp ajax urlhow to filter wordpress page using ajaxadd html ajax filter wordpresswordpress custom ajax filterwordpress ajax url in jquerywordpress filter ajax postmake ajax calls in wordpress pagewordpress plugin ajax posthow to ajax in wordpresswordpress is ajax callphp function ajax wordpresswp ajax filteradd ajax function wordpressajax on wordpresswordpress ajax simple examplejquery wordpress simple ajaxwordpress ajax postwordpress ajax return codewordpress ajax hookwordpress plugin submit ajaxhow to call php file using ajax in wordpressfilters for custom post type ajaxhow to use ajax in wordpress pluginajax wordpressadd ajax to wordpress function phpwordpress work with ajax call admin sideajax php wordpressmake a ajax in wordpresswordpress ajax request in 22javascript 22simple ajax category filter wordpresshow to tset ajax in wordpresshow to create ajax filter in wordpresswordpress ajax filter codewordpress ajax example codehow to wordpress ajaxajax script html wordpressajax filter in wordpresshow to filter wordpress page in use ajaxwordpress ajax in wordpress code customhow to do wordpress ajaxcall ajax function in wordpresswordpress ajax filter posts by custom fieldswordpress ajax call to functions phpadd non ajax wordpresswordpress ajax run functionwordpress ajax post filter dropdown without pluginwordpress using ajax to filter postswhy wordpress ajax when we can use ajax alonewordpress trigger ajaxwordpress custom ajax functionjquery filter for wordpresswordpress function ajax action phpwordpress create ajax filtercreate ajax request function in functions php 2b wordpresswordpress ajaxcode ajax wordpresswordpress ajax data on click wp ajax in wordpressjquery filter in javascript in wordpressajax link wordpresswordpress plugin ajax directly no add actionwordpress ajax javascript requestwp ajax filter postscreate ajax request wordpresswordpress jquery ajax exampleajax request in wordpress plugin developmentwordpress ajax the right waywp ajax wordpresswp ajax filter actionswordpress ajax requestwordpress ajax tutorialshow posts by custom fields ajax filterhow to use ajax to filter in wordpresswordpress ajax post filter selectwordpress jquery ajax3 steps to create ajax post filterssetting up ajax on wordpresswordpress ajax url in frontendwordpress jquery ajax posthow to use ajax in wordpress using jsbuilt in ajax wordpressajax in wordpress