Answer the question
In order to leave comments, you need to log in
Wordpress filter not working?
Hello everyone, I made a filter according to this instruction wp-kama.ru/id_652/dinamicheskiy-arhiv-bloga-s-ispo... and it doesn't work. I have a product type tovary, a proizvoditel taxonomy, and a kategorii taxonomy.
here is the tpl_archive.php template code
<?php
/*
Template Name: Шаблон архивов
*/
?>
<?php get_header(); ?>
<style type="text/css" rel="stylesheet" >
#archive_browser > div { display: inline-block; padding-right: 10px; }
#archive_pot { min-height:150px; }
#archives_table { border-collapse:collapse; margin:15px 0 0 0; width:100%; }
#archives_table td { min-height:25px; padding:4px; border-top:1px solid #eee; border-bottom:1px solid #eee; }
</style>
<script type="text/javascript">
(function($){
$(function(){
$("#archive_browser select").change(function(){
$("#archive_pot")
.empty()
.html("<div style='text-align:center; padding:30px;'><img src='<?php bloginfo('template_url') ?>/img/preloader.gif' /></div>");
var dateArray = $("#month-choice").val().split("/");
var y = dateArray[3];
var m = dateArray[4];
var c = $("#cat").val();
$.post(
"<?php bloginfo('template_url') ?>/archive_getter.php",
{
year : y,
month : m,
cat : c
},
function(data) {
$("#archive_pot").html(data).animate({ height: $("#archives_table").height()+40 });
}
);
});
});
})(jQuery)
</script>
<div id="archive_browser">
<select id="month-choice">
<?php $posts = get_posts( array(
'post_type' => 'tovary',
) );
foreach($posts as $post){ setup_postdata($post);
echo '<option>'.get_the_term_list($post->ID,'proizvoditel').'</option>';
}
wp_reset_postdata(); ?>
</select>
<select>
<?$posts = get_posts( array(
'post_type' => 'tovary',
) );
foreach($posts as $post){ setup_postdata($post);
echo '<option>'.get_the_term_list($post->ID,'kategorii').'</option>';
}
wp_reset_postdata(); ?>
</select>
</div>
<div id="archive_pot"></div>
<?php get_footer(); ?>
<?// подгружаем среду WP
require($_SERVER['DOCUMENT_ROOT'].'/wp-load.php');
// фильтруем POST данные, передаваемые этому файлу с Javascript
$year = htmlspecialchars(trim($_POST['year']));
$month = htmlspecialchars(trim($_POST['month']));
$cat = htmlspecialchars(trim($_POST['cat']));
?>
<table id="archives_table">
<?php if( ($year=='') && ($month=='') && ($cat=='-1') ){
echo "<tr><td style='text-align: center; font-size: 15px; padding: 5px;'>Пожалуйста, выберите дату/категорию из списка выше.</td></tr>";
}
else
{
// Получаем данные с помощью query_posts
$args1 = array(
'post_type' => 'tovary',
'tax_query' => array(
'relation' => 'OR',
array(
'taxonomy' => 'proizvoditel',
'field' => 'id',
'operator' => 'AND',
),
array(
'taxonomy' => 'kategorii',
'field' => 'id',
'operator' => 'in',
)
)
);
query_posts( $args1 );
// выводим данные в Цикле WordPress
if( have_posts() ){
while( have_posts() ){
the_post(); ?>
<tr>
<td><a href='<?php the_permalink(); ?>'><?php the_title(); ?></a></td>
<td><?php the_post_thumbnail(array (130, 130)); ?></td>
</tr>
<?php
}
}else
echo "<tr><td style='text-align: center; font-size: 15px; padding: 5px;'>Ничего не найдено.</td></tr>";
} ?>
</table>
Answer the question
In order to leave comments, you need to log in
Hello.
You decompose the problem. It’s so hard to understand right away where and what doesn’t plow. It is possible that there are bugs in several places, you just do not see them.
1) Start debugging from the client side. Test your js functions. Whether they send data to the server.
2) If the data comes to the handler, test query_posts. You need to test to return the correct data set.
3) If query_posts returns the correct data, then test the data output logic.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question