query variable – query_vars not preserving GET requests in pagination


I’ve added custom query variables with the function below and when a request is made to https://www.example.com/faqs/?topic=Some+Subject, it returns a list of posts.

function add_query_vars( $public_vars ) {
    $public_vars[] = 'topic';
    return $public_vars;
add_filter( 'query_vars', 'add_query_vars' );

If there are more than 10 posts for example, there’s pagination at the bottom. When I hover over 2 page for instance, the URL reads https://www.example.com/faqs/page/2/?topic=Some+Subject.

When I click on it though, it changes to https://www.example.com/faqs/page/2/?topic=Some%20Subject. I get that its being URL encoded but I now no longer see the results related to topic=Some+Subject and it displays all the posts and the additional paging numbers e.g. 3, 4 and so on.

What is the solution to preserve the results for the query variable during paging?

Ryan 2 months 2022-10-15T13:33:58-05:00 0 Answers 0 views 0

Leave an answer