我想覆盖 CMS 中指定的发布限制(设置为 12)。我在参数中添加了“posts_per_page”,这是我在 Wordpress Codex 中找到的,但它不起作用。
此搜索代码来自 CookingPress 主题。
问题:为什么参数 'posts_per_page' => 24 不起作用?
<?php
if ($_GET['submit']) {
$args = array(
'posts_per_page' => 24,
'tax_query' => array(
'relation' => 'AND'
)
,'post_type' => 'post'
);
$cat = mysql_real_escape_string($_GET['cat']);
$categories = array();
if($cat) {
$categories = array (
'taxonomy' => 'category',
'field' => 'term_id',
'terms' => array( $cat )
);
array_push($args['tax_query'],$categories);
}
$level = mysql_real_escape_string($_GET['level']);
$levels = array();
if($level) {
$levels = array (
'taxonomy' => 'level',
'field' => 'slug',
'terms' => array( $level )
);
array_push($args['tax_query'],$levels);
}
$serving = mysql_real_escape_string($_GET['serving']);
if($serving) {
$servings = array (
'taxonomy' => 'serving',
'field' => 'slug',
'terms' => array( $serving )
);
array_push($args['tax_query'],$servings);
}
$time = mysql_real_escape_string($_GET['timeneeded']);
if($time) {
$times = array (
'taxonomy' => 'timeneeded',
'field' => 'slug',
'terms' => array( $time )
);
array_push($args['tax_query'],$times);
}
$allergen = $_GET['allergens'];
if($allergen) {
$allergens = array (
'taxonomy' => 'allergen',
'field' => 'slug',
'terms' => $allergen
);
array_push($args['tax_query'],$allergens);
}
$tags = $_GET['include_ing'];
if($_GET['relation']=='all') {
if($tags) {
foreach ($tags as $t) {
$tagsquery = array (
'taxonomy' => 'post_tag',
'field' => 'slug',
'terms' => mysql_real_escape_string($t)
);
array_push($args['tax_query'],$tagsquery);
}
}
} else {
if($tags) {
$tagsquery = array (
'taxonomy' => 'post_tag',
'field' => 'slug',
'terms' => $tags
);
array_push($args['tax_query'],$tagsquery);
}
}
$extags = $_GET['exclude_ing'];
if($extags) {
$extagsquery = array (
'taxonomy' => 'post_tag',
'field' => 'slug',
'terms' => $extags,
'operator' => 'NOT IN'
);
array_push($args['tax_query'],$extagsquery);
}
if(!$wp_query) global $wp_query;
$args = array_merge( $args , $wp_query->query );
query_posts( $args);
}
?>