Im baffled on why this is not showing the correct results, when selecting the month alone and say 100 posts are on the site, only 3 show up, then if you select the category and month the proper show up.
here is the archives template
<div id="archive-browser">
<div>
<h4>Month</h4>
<select id="month-choice">
<option val="no-choice"> — </option>
<?php wp_get_archives(array('type' => 'monthly', 'format' => 'option')); ?>
</select>
</div>
<div>
<h4>Category</h4>
<?php wp_dropdown_categories('show_option_none= -- ');?>
</div>
</div>
<div id="archive-wrapper">
<div id="archive-pot"></div>
</div>
here is the archives getter
<?php
/*
Template Name: Archives Getter
*/
$year = trim($_POST['digwp_y']);
$month = trim($_POST['digwp_m']);
$cat = trim($_POST['digwp_c']);
$querystring = "year=$year&monthnum=$month&cat=$cat&posts_per_page=-1";
query_posts($querystring);
?>
<?php if (($year == '') && ($month == '') && ($cat == '-1')) { ?>
<table id="archives-table"><tr><td style='text-align: center; font-size: 15px; padding: 5px;'>Please choose from above.</td></tr></table>
<?php } else { ?>
<table id="archives-table">
<?php
if (have_posts()) : while (have_posts()) : the_post(); ?>
<tr>
<td><img src="<?php echo get_post_meta($post->ID, 'PostThumb', true); ?>" alt="" style="width: 35px;" /></td>
<td><a href='<?php the_permalink(); ?>'><?php the_title(); ?></a></td>
<td><?php comments_popup_link(' ', '1 Comment', '% Comments'); ?></td>
<td><?php the_date('m/j/Y'); ?></td>
</tr>
<?php
endwhile; else:
echo "<tr><td style='text-align: center; font-size: 15px; padding: 5px;'>Nothing found.</td></tr>";
endif;
?>
</table>
and finally the jquery code
jQuery(function($) {
$("#archive-wrapper").height($("#archive-pot").height());
$("#archive-browser select").change(function() {
$("#archive-pot")
.empty()
.html("<div style='text-align: center; padding: 30px;'>loading...</div>");
var dateArray = $("#month-choice").val().split("/");
var y = dateArray[3];
var m = dateArray[4];
var c = $("#cat").val();
$.ajax({
url: "/archive-getter/",
dataType: "html",
type: "POST",
data: ({
"digwp_y": y,
"digwp_m" : m,
"digwp_c" : c
}),
success: function(data) {
$("#archive-pot").html(data);
$("#archive-wrapper").animate({
height: $("#archives-table tr").length * 50
});
}
});
});
});
this is what i ended up with which works nicely.
functions.php part
jquery part
It is going to be difficult to debug something like this since I don’t have your data on my server but you are doing several things that strike me as dicey.
First, you are using
query_posts
. Do not usequery_posts
.Second, you are running your query before you check to see if you want to run a query. That is, before this line:
Why would you run a query and then check to see whether you want to tell user they haven’t filled in all the requirements they for the query to run?
Third, this…
… is a strange condition. If is
false
if$cat
is empty. Presumably, your form sets that value to-1
but that brings me to…Fourth, you appear to be trusting user supplied data 100%.
POST
is no more (maybe 1% more) secure thanGET
. Unless there is validation somewhere not posted, a malicious user could potentially push unsafe data through that query.Fifth, you are not using the AJAX API and this is exactly the kind of thing it is meant for.