i'm using Wordpress as content management system and my template has a div with box
class, and contains a dropdown list . my goal is getting the value of this droplist and query post in ajax method with this value,then reload just box
div using ajax , for getting more clear here is markup :
<select>
<option value="1">Item 1</option>
<option value="2">Item 2</option>
<option value="3">Item 3</option>
<option value="4">Item 4</option>
</select>
------------------
<div class="content">
<?php
$args = array(
"meta_query" => array(
array(
'key' => 'meta',
'value' => '$select_value',
)
)
);
query_posts( $args );
?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile; else: ?>
<p>sorry no post found with this value.</p>
<?php endif; ?>
i think sample code is clear , but i want to do this processes:
user select an item in dropdown list --> get select value --> put it in $select_value --> run query --> show the div box
without reloading entire page using ajax...
Can someone help me out writting this?
For this to achieve you should have knowledge of Admin Ajax in wordpress.
Admin Ajax: in your header.php
in you custom js file
my-custom.js, enqueue the js file
In your function.php
make the required changes, as I can't post the whole code for you, make some efforts and the above code will help you get an idea that how it's going to work.