admin管理员组文章数量:1435510
I'm running some template files outside of the actual theme and I am displaying some posts on this templates. Everything worked absolutely fine but some days ago (maybe the update to 4.5) the default settings of WordPress started to override my posts_per_page=-1
and I have no clue why this is starting. (No new plugins installed)
<?php
// Include WordPress
define('WP_USE_THEMES', false);
require('./../wp-blog-header.php');
query_posts('tag=tagname&posts_per_page=-1');
?>
<?php while (have_posts()): the_post(); ?>
<section class="in_tab">
<figure class="tab_fig">
<?php the_post_thumbnail('thumbnail'); ?>
</figure>
<h2><?php the_title(); ?></h2>
<a class="insidelink" target="_blank" href="<?php the_permalink(); ?>" >Weiter...</a>
</section>
<?php endwhile; ?>
I'm running some template files outside of the actual theme and I am displaying some posts on this templates. Everything worked absolutely fine but some days ago (maybe the update to 4.5) the default settings of WordPress started to override my posts_per_page=-1
and I have no clue why this is starting. (No new plugins installed)
<?php
// Include WordPress
define('WP_USE_THEMES', false);
require('./../wp-blog-header.php');
query_posts('tag=tagname&posts_per_page=-1');
?>
<?php while (have_posts()): the_post(); ?>
<section class="in_tab">
<figure class="tab_fig">
<?php the_post_thumbnail('thumbnail'); ?>
</figure>
<h2><?php the_title(); ?></h2>
<a class="insidelink" target="_blank" href="<?php the_permalink(); ?>" >Weiter...</a>
</section>
<?php endwhile; ?>
Share
Improve this question
edited Apr 23, 2016 at 9:43
Max Yudin
6,3882 gold badges26 silver badges36 bronze badges
asked Apr 23, 2016 at 8:48
SteveSteve
1503 silver badges11 bronze badges
4
|
2 Answers
Reset to default 2Regarding my comment to Steve's answer, see also Override the default number of posts to show for a single loop? The "method" version of Steve's answer would be:
function limit_posts_per_archive_page( $query ) {
if ( $query->is_post_type_archive( 'zitate-sprueche' ) || $query->is_tax('zitate-kats') || $query->is_post_type_archive('daten') || $query->is_tax('daten-kats')) {
$limit = 27;
} else
$limit = get_option('posts_per_page');
}
$query->set( 'posts_per_archive_page', $limit );
}
add_action( 'pre_get_posts', 'limit_posts_per_archive_page' );
Similar code works for me.
I found the problem. Here is the solution in case someone stumbles upon a similar problem.
I had a filter in my functions.php that limited the showed posts on several custom taxonomies and the default value was set in the else statement
// Customizing posts per page on zitate archive
function limit_posts_per_archive_page() {
if ( is_post_type_archive( 'zitate-sprueche' ) || is_tax('zitate-kats') || is_post_type_archive('daten') || is_tax('daten-kats')) {
$limit = 27;
}
else if (is_post_type_archive( 'videos' ) || is_tax('videos-kats') || is_post_type_archive( 'whitepaper' ) || is_tax('whitepaper-kats')) {
$limit = 9;
}
else
$limit = get_option('posts_per_page');
set_query_var('posts_per_archive_page', $limit);
}
add_filter('pre_get_posts', 'limit_posts_per_archive_page');
I changed the else to
else {
// do nothing :)
}
Now it works as usual
本文标签: query postspostsperpage override by default settings
版权声明:本文标题:query posts - posts_per_page override by default settings 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745642617a2667948.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
[23-Apr-2016 10:16:25 UTC] PHP Notice: WP_Query wurde mit einem Parameter oder Argument aufgerufen, der seit Version 3.1 <strong>veraltet ist</strong>! „caller_get_posts“ ist veraltet. Bitte benutze stattdessen „ignore_sticky_posts“. in .../wp-includes/functions.php on line 3846
English version: WP_Query was uses an deprecated argument or parameter „caller_get_posts“ instead use „ignore_sticky_posts“ – Steve Commented Apr 23, 2016 at 10:17