• Ati74

    (@ati74)


    Hi,

    today i have a strange problem. It´s my first try with WordPress & Ajax, but the most works… except a little part.
    The Mainfunction is that after a few inputs in a form under the form some entries should be visible. With the Inputs i build a query like that

    $table_plztour = $wpdb->prefix . "za_plztour";
    	$zeit = $_POST['zeit'];
    	$ortid = $_POST['ortid'];
    	$lkw = wp_strip_all_tags($_POST['tournr']);
    	$datum = $_POST['datum'];
    	$plz = $wpdb->get_var ( "SELECT plz FROM $table_plztour WHERE id=$ortid" );
    	$ort = $wpdb->get_var ( "SELECT ort FROM $table_plztour WHERE id=$ortid" );
    	echo 'Die Zeit: '.$datum.' um '.$zeit.'<br>';
    	echo 'Der Ort: '.$plz.' '.$ort . ' für Tour '.$lkw.'<br>';
    	$meta_query = array();
    	if (!empty($datum)) {
    				$meta_query[] = array(
    				'key' => '_lieferdatum',
    				'value' => $datum,
    				'compare' => '='
    				);
    
    			}
    
    			if (!empty($lkw)) {
    				$meta_query[] = array(
    				'key' => '_tour',
    				'value' => $lkw,
    				'compare' => 'LIKE'
    				);
    
    			}
    
    			$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
    			$argus=array(
    				'post_type' => 'liefertermin',
    				'posts_per_page' => 10,
    				'paged' => $paged,
    				'meta_query' => $meta_query
    			);
    			$wp_query = new WP_Query($argus);

    The Problem is this Part

    if (!empty($lkw)) {
    				$meta_query[] = array(
    				'key' => '_tour',
    				'value' => $lkw,
    				'compare' => 'LIKE'
    				);
    
    			}

    If i change $lkw to e.g. ‘502’ everything works fine. If i used $lkw
    the Query return no results! I do not know where the error is 🙁

    Ati74

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Ati74

    (@ati74)

    It seems that i found the “error”. The varable $lkw comes from an Input-Field, which is setting by jQuery. There is something stupid. After i select a postal code from a dropdownlist the Value is setting by jQuery (e.g. 502), if i write 502 manually in the input-field everything works fine. Here ist the jquery-code

    $('#lieferort').change(function(){
    
    		var meinplz = $(this).val();
    		var data = {
    		action: 'lieferort_plz',
    		plz: meinplz
    		};
    		 $.post(lieferterminajax.ajaxurl, data, function(resp) {
    			//jQuery('input[name="tour"]').val(resp);
    			jQuery('#tournummer').val(resp);
    
    		});

    What can i do?

    Dion

    (@diondesigns)

    If your script is being minified, it will not work correctly due to your commenting out a line using //double-slash. That will comment out all code until an EOL character is reached. Since minified code contains no EOL characters, you are effectively commenting out all code in the script after the //double-slash.

    In this day and age, //double-slash should never be used for comments in javascript. Instead of this:

    // Here is a JS comment

    one should use this:

    /* Here is a JS comment */

    to insure the script will work if it is minified.

    Thread Starter Ati74

    (@ati74)

    Thanks for your answer…but this was not the solution.
    Anyway there was a logical bug exists, so i do everything new.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘WP-Query doesn´t work with variable’ is closed to new replies.