I implemented a pagination using paginate_links() like below:

function wpse229670_pagination( $query = false ) {
    global $wp_query;
    $query = $query ? $query : $wp_query;

    $total_pages = $query->max_num_pages;
    $big = 999999999;
    if ( $total_pages > 1 ) {
        echo '<nav class="navigation posts-navigation" role="navigation">';
            echo '<strong>'. __( 'Pages:', 'text-domain' ) .'</strong> ';
            echo paginate_links( array(
                        'base' => ,
                        'format' => '?paged=%#%',
                        'current' => max( 1, get_query_var('paged') ),
                        'total' => $total_pages
                    ) );
        echo '</nav>';

    } //endif ( $total_pages > 1 )


And I can easily display my pagination using wpse229670_pagination(); within loop, or for any custom loop, I can pass the local query as a parameter.

It's working fine.

Scenario is, I'm adding some query args like this to display a modal warning to the user:

$terms = wp_get_post_terms( $post_id, 'my_tax' );
$term_link = get_term_link( $term_id, 'my_tax' );
$parameterized_url = add_query_arg( 'from_expired', 1, $term_link );


But the pagination links continue to display the warning, as because I cannot remove_query_arg() from the query and the following pages contains the argument as well.

I think it would be better if I can remove necessary [one time] query_args inside my pagination function. You know I cannot do:

//$query = remove_query_arg( 'from_expired', $query );

because $query inside my function is an object.

So, how can I remove_query_arg() from a $wp_query object or from paginate_links()?

1 Answer 1


Not sure if you mean this kind of approach:

add_filter( 'paginate_links', function( $link )
       filter_input( INPUT_GET, 'from_expired' )
       ? remove_query_arg( 'from_expired', $link )
       : $link;
} );

to remove the from_expired from the pagination links if it's in the current GET query.

  • Not necessary how I meant it. A working solution was necessary. +1 for the solution. Working on the first hit. Thanks a lot :) Jun 14, 2016 at 10:42
  • There might be a way to only apply this to your custom pagination function, I first forgot a ; but I added that to the code, so you probably tried the fixed version. Glad to hear it somewhat worked for you ;-) @MayeenulIslam
    – birgire
    Jun 14, 2016 at 10:50
  • I copied the concept, not the code itself - that might be the issue. ;-) Jun 15, 2016 at 15:48
  • 1
    That sounds like a good general advise on how to use this site, conceptually ;-) @MayeenulIslam
    – birgire
    Jun 15, 2016 at 16:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.