• Hello All,

    I wanted to add pagination for a list of data for my custom endpoint in my accounts tab.

    I added endpoint with:

    add_action( ‘woocommerce_account_license_endpoint’, ‘my_account_endpoint_content’ );

    and then html with anchor tag:

    echo '<a href="https://test-X.com/account/license/?page=1"> Test </a>';

    however, it keeps on bringing me back to https://test-X.com/account instead of submitting as a query string to the same page, I tried to type it manually in url it also bring me to the account page, any idea?

    Any help will be appreciated! Thanks

    • This topic was modified 3 years, 7 months ago by bcworkz.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    WP is trying its best to match the request to anything it already has. What purpose does /license/ serve? Is that one of the tabs? It’d be best to take that out of the URL and include it in the query string. If it’s really important to be part of the URL, you may need an explicit rewrite rule to convert it to a query string behind the scene.

    Thread Starter herng77

    (@herng77)

    Yes, it is one of the tabs. Now, I am able to surf to https://test-X.com/account/license/?page=1 without stripping the page query, but when I tried to get data with $_GET[“page”], I am unable to get any data, am I doing anything wrong? I even tried to use get_query_vars.

    if (!isset ($_GET['page']) ) {  
            $page = 1;  
        } else {  
            $page = $_GET['page'];  
    
    }

    This is the latest code

    Moderator bcworkz

    (@bcworkz)

    It’s hard to say without knowing how WP gets to your code. Things can happen to query string data along the way. I cannot explain why $_GET[‘page’] is unavailable. It might be WP considers it a reserved query var for other purposes.

    What if the query var was “herng-page”? Same issue or fixed?

    The other thing you can do is whitelist your unique, unreserved query var through the “query_vars” filter (just add it to the passed array). Then get_query_var() will work. This would be the preferred way over $_GET anyway. But avoid generic query var names like “page” ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Query String for Custom Endpoint in My Accounts Tab’ is closed to new replies.