Question list paging – re-using blog max items paging setting doesn't make sense

I would like to keep blog paging at max 6, but Q&A is a completely different section and reusing 6 there doesn’t make any sense. Is an admin setting to override this planned or do I have to go ahead and write my own pre_get_posts() filter?

  • Hakan
    • The Incredible Smush

    Hi lkraav,

    Your question is about Q&A plugin, is that right?

    As written in the settings page of the plugin:

    Note that Questions Per Page is controlled by WordPress Blog pages show at most setting, not by the plugin.

    This is not because we are reluctant to add this option, but because pagination support on page templates have limitations by WordPress itself.

    More clearly, it is not possible to set a Questions Per Page setting less than “Blog pages show at most” setting.

    In your case, I feel that you want a greater number than the global post per page setting and here is the solution for that. Just add the following lines on top of default-templates/archive-question.php:

    <?php
    /* CUSTOM Questions Per page setting
    IMPORTANT!!!
    Posts per page here should be equal to or GREATER THAN than "Blog pages show at most" setting
    */
    global $wp_query;
    $wp_query->query_vars['posts_per_page'] = 10; // This is the Questions Per Page
    query_posts( $wp_query->query_vars );
    ?>

    To emphasize it once more, Questions Per Page should be equal to or greater than “Blog pages show at most” setting.

    I hope this helps.

    Cheers,

    Hakan

  • Hakan
    • The Incredible Smush

    No, I haven’t seen that and I think it is a better solution as you can add it in functions.php of your theme, being safe on plugin updates.

    I tested this and it worked fine for me:

    add_action('pre_get_posts', 'custom_question_per_page');
    function custom_question_per_page( $query ){
    if( $query->get('post_type') == 'question' ) {
    $query->set('posts_per_page', 15);
    }
    }

    Cheers,

    Hakan

  • Hakan
    • The Incredible Smush

    In fact I like that solution so much that I decided to integrate it into the next version :slight_smile:

    If you don’t need an urgent solution for that, you can wait for the next version.

    Thank you for pointing out that :slight_smile:

    Cheers,

    Hakan

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.