WordPress.org

Ready to get started?Download WordPress

Forums

Trying to append a value to permalink... (13 posts)

  1. Jim R
    Member
    Posted 3 years ago #

    The WP Page is called Teams, and I have a table of data from my database. I want my Users to be able to sort via each column, but I don't think the 'sortby' values are being passed when the User clicks on the column header.

    <table width="100%" class="first_impressions">
          <tr>
            <td width="21%"><b><a href="/teams?sortby=coachLast">Name</a></b></td>
            <td width="23%"><b><a href="/teams/?sortby=school">High School</a></b></td>
            <td width="13%"><b><a href="/teams/?sortby=sectional">Sectional</a></b></td>
            <td width="8%"><b><a href="/teams/?sortby=class">Class</a></b></td>
            <td width="35%"><b><a href="/teams/?sortby=email">Email</a></b></td>
          </tr>
          <tr>
            <td>
    
    <?php
    
    if (!isset($_GET['sortby'])) {
    $sortby = "sectional";
    $query = 'SELECT * FROM hhr_schools ORDER BY '. $sortby .' ASC';
    }
    else {
    
    $sortby = $_GET['sortby'];
    $query = 'SELECT * FROM hhr_schools ORDER BY '. $sortby .' ASC, nameLast ASC';
    }
  2. vtxyzzy
    Member
    Posted 3 years ago #

    I am not using pretty permalinks, so I had to use a page_id in the links, and my site name is 'test', so the links look like this:

    <td width="21%"><b><a href="/test/?page_id=206&sortby=coachLast">Name</a></b></td>

    but that works for me.

  3. Jim R
    Member
    Posted 3 years ago #

    That's not working. Is there a certain way I should have my permalinks set up for Pages?

  4. vtxyzzy
    Member
    Posted 3 years ago #

    Can you post a link to your site so I can see the generated html?

    Did you use your own site name and page_id?

    I have tried this with both the default and 'pretty' permalinks. It works both ways. But, I am testing on a local install, so it may be different on a remote host. You may need to use the whole url rather than just the relative one.

  5. Jim R
    Member
    Posted 3 years ago #

    http://hoosierhoopsreport.com/teams/

    I haven't checked the code in the browser yet. :(
    I'll do that when I get back.

  6. vtxyzzy
    Member
    Posted 3 years ago #

    The links seem to be pointing to the correct page, with the correct 'sortby' arg.

    But, I noticed that in the code snippet you posted that you used 'nameLast' in the ORDER BY clause, but when I hover over 'Name' in the page, I see 'coachLast'. Is 'nameLast' really a column in the table? If not, your order by is probably being ignored.

    Have you tried printing out a message showing the sortby arg?

    <?php
    
    echo "<h2>SORTBY:{$_GET['sortby']}</h2>";
    
    if (!isset($_GET['sortby'])) {
    $sortby = "sectional";
  7. Jim R
    Member
    Posted 3 years ago #

    Yes, the code snippet was corrected since posting that code.

    I just printed the sortby arg, but it's blank. It's not passing the code.

  8. vtxyzzy
    Member
    Posted 3 years ago #

    It may be theme related. I saw a similar problem where the arg 'year' was not passed because it was 'registered' with WP (also with 'paged'). Try changing the arg to mysortby or something else really unique.

  9. Jim R
    Member
    Posted 3 years ago #

    I changed it. It's still not passing the variable. :(

  10. vtxyzzy
    Member
    Posted 3 years ago #

    Last thing I can think of - switch to the default theme and see if it works there.

  11. Jim R
    Member
    Posted 3 years ago #

    It still didn't work.

  12. Jim R
    Member
    Posted 3 years ago #

    I even changed to the Default permalink setting. It's just not passing the appended variable. I'm wondering if being a Page vs. a Post changes how that works.

  13. vtxyzzy
    Member
    Posted 3 years ago #

    I tested it on a Page that I use for testing code snippets and it worked there. Maybe some plugin is filtering the query.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags