Skip to content

Instantly share code, notes, and snippets.

@joshmoto
Last active December 11, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshmoto/4612377 to your computer and use it in GitHub Desktop.
Save joshmoto/4612377 to your computer and use it in GitHub Desktop.
This is my php file which will load in via ajax when my form is submitted...
<?php
define('WP_USE_THEMES', false);
require ('/home/sites/mysite.co.uk/www/wp/wp-load.php');
$ajaxCounty = $_GET['varCounty'];
$ajaxTown = $_GET['varTown'];
$dealerResults = new WP_Query(array(
'post_type' => 'dealer',
'meta_query' => array(
array(
'key' => 'dealer_county',
'value' => $ajaxCounty,
'compare' => '='
),
array(
'key' => 'dealer_town',
'value' => $ajaxTown,
'compare' => '='
)
)
));
?>
<?php if ($dealerResults->have_posts()) : ?>
<div class="dealer-wrapper">
<?php while ($dealerResults->have_posts()) : $dealerResults->the_post(); ?>
<h1><?php the_title ?></h1>
<ul>
<?php
$address1 = get_post_meta($post->ID, 'dealer_address_1', true);
if($address1) {
echo '<li>' . $address1 . </li>';
}
$address2 = get_post_meta($post->ID, 'dealer_address_2', true);
if($address2) {
echo '<li>' . $address2 . </li>';
}
$address3 = get_post_meta($post->ID, 'dealer_address_3', true);
if($address3) {
echo '<li>' . $address3 . </li>';
}
$address4 = get_post_meta($post->ID, 'dealer_address_4', true);
if($address4) {
echo '<li>' . $address4 . </li>';
}
$town = get_post_meta($post->ID, 'dealer_town', true);
if($town) {
echo '<li>' . $town . </li>';
}
$county = get_post_meta($post->ID, 'dealer_county', true);
if($county) {
echo '<li>' . $county . </li>';
}
$postcode = get_post_meta($post->ID, 'dealer_postcode', true);
if($postcode) {
echo '<li>' . $postcode . </li>';
}
?>
</ul>
<?php endwhile; ?>
</div>
<?php unset($dealerResults); endif; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment