Site logo

[Resolved] Pagnation

Home Forums Support [Resolved] Pagnation

Home Forums Support Pagnation

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #2546718
    Kevin

    Hello-

    When I first started with GP I was having pagination issues and I believe on of the moderators gave me the following to use to correct the problem

    function remove_page_from_query_string($query_string)
    {
    if ($query_string[‘name’] == ‘page’ && isset($query_string[‘page’])) {
    unset($query_string[‘name’]);
    $query_string[‘paged’] = $query_string[‘page’];
    }
    return $query_string;
    }
    add_filter(‘request’, ‘remove_page_from_query_string’);

    Fast forward to 2023, I’m getting the following error’s per my host:

    2023/02/22 03:27:28 [error] 123236#123236: *261645 FastCGI sent in stderr: “PHP message: PHP Warning: Undefined array key “name” in /www/XXXXXXXXX/public/wp-content/plugins/code-snippets/php/snippet-ops.php(505) : eval()’d code on line 3″ while reading response header from upstream, client: 35.236.17.54, server: http://www.XXXXXX.com, request: “HEAD /XXXXXXXXXX/ HTTP/1.1”, upstream: “fastcgi://unix:/var/run/php8.0-fpm-XXXXXXX.sock:”, host: “XXXXXXXXX”, referrer: “https://XXXXXXXXXXX”

    The plugin author suggested I update the code to the following. My question is this; does this look ok to you, any potential issues I should be aware of? Thanks!

    add_filter( ‘request’, function ( $query_string ) {
    if ( isset( $query_string[‘page’], $query_string[‘name’] ) && ‘page’ === $query_string[‘name’] ) {
    unset( $query_string[‘name’] );
    $query_string[‘paged’] = $query_string[‘page’];
    }
    return $query_string;
    } );

    #2546926
    Kevin

    bump

    #2547296
    David
    Staff
    Customer Support

    Hi there,

    the code looks good to me, it just introduce another check to make sure that both query vars ( page & name ) are set, which should resolve that warning.

    #2547571
    Kevin

    Awesome, super appreciate the help…have a great day!

    #2547583
    David
    Staff
    Customer Support

    You’re welcome – and you too!

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.