[英]Change posts_per_page with button/input
I know there's a wordpress stackexchange but yeah, no ones helping.我知道有一个 wordpress stackexchange 但是是的,没有人帮忙。
I was wondering if it was possible to change the number of posts emitted from a custom loop based on a button form?我想知道是否可以根据按钮表单更改从自定义循环发出的帖子数量?
What I gathered so far (test values):到目前为止我收集的内容(测试值):
<form method="post">
<button class="amt-button" name="amt_per" value="1">1</button>
<button class="amt-button" name="amt_per" value="3">3</button>
<button class="amt-button" name="amt_per" value="0">0</button>
<button class="amt-button" name="amt_per" value="-1">all</button>
</form>
<script>
jQuery(document).ready(function($) {
// Postsperpage
$('button.amt-button').click(function(){
$(this).closest('form').submit();
});
});
</script>
Also the WP_Query (the $args):还有 WP_Query($args):
$args = array(
'post_type'=>'product',
'posts_per_page' => $postperpage,
'product_cat'=>'product',
'product_tag'=>'apparel',
'orderby'=>$orderby,
'order'=>$order,
'meta_key'=>$meta_key,
'paged' => $paged
);
Something like:就像是:
$postsperpage = isset($_POST['amt_per'])? $_POST['amt_per']: -1;
Then in your WP_Query
arg然后在你的
WP_Query
arg
'posts_per_page' => $postsperpage
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.