最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

query posts - posts_per_page override by default settings

matteradmin8PV0评论

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
  • I don't see any changes to inline documentation for it and it would be extremely unlikely for WP to change existing argument. – Rarst Commented Apr 23, 2016 at 9:50
  • check the error_log and post its output :) – Nabeel Khan Commented Apr 23, 2016 at 10:00
  • the only error i get is: [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
  • pls excuse my scrappy english in the comment above :) – Steve Commented Apr 23, 2016 at 10:34
Add a comment  | 

2 Answers 2

Reset to default 2

Regarding 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

Post a comment

comment list (0)

  1. No comments so far