wordpress - Handling URLs correctly with PHP


i have the following case within my plugin for wordpress: I have a details page of a database entry which can be accessed like this:


The next would be to add sorting options to this page and i solved it with this code:

The url would be:


      if (!empty($_GET['orderby'])) {
        $pos = strpos($_SERVER["REQUEST_URI"], 'orderby');
        $url = substr($_SERVER["REQUEST_URI"], 0, $pos-1); 
        if ($_GET['order'] == 'desc') {
          echo '<th >';
          echo '<a href="'.$url.'&orderby=answer&amp;order=asc">';
        } else {
          echo '<th >';
          echo '<a href="'.$url.'&orderby=answer&amp;order=desc">';
      } else {
        echo '<th >';
        echo '<a href="'.$_SERVER["REQUEST_URI"].'&orderby=answer&amp;order=asc">';

This works fine, but do i have to do that URL/REQUEST_URI stuff or is there a solution which is much simpler?


People are also looking for solutions to the problem: php - Level & Exp Point System


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.