Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Can you append values to the end of a url?

  • This topic is empty.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #35646
    jacorre
    Participant

    I’m working in WordPress and I have a custom search that grabs values from the form and then creates a header(Location:…) url with it. For example, ?taxonomy1=whatever&taxonomy2=whatever.

    I was looking for a way to provide the user with sort options once they’ve done a search.

    I know that if I type orderby and order parameters in the url it works. Basically if I type orderby=title&order=asc to the end of the current url it works perfectly.

    So I was looking for a way to append those to the url when a user selects the sort option from a drop down. So it would end up being ?taxonomy1=whatever&taxonomy2=whatever&orderby=title&order=asc.

    The problem I’m running into is that the previous parameters that were posted to the url no longer remain once I try to append the orderby and order parameters.

    For example, I tried using:

    Order By Title (ASC)

    That works great on the current url you’re on like if you visited an archive page. But if that url contained search parameters like it would when performing my custom search, it won’t work because those previous search parameters are removed and you’re left with the root url with the orderby and order parameters appended to the end.

    #92746
    thebreiflabb
    Member

    Hello, I haven’t really used wordpress much, but I know some PHP. Top of my head I figured this should work:

    orderby=title&order=asc">Order By Title (ASC)

    This checks wether there is already any parameters in the URL and outputs what fits. Hope it helps :-)

    #92748
    jacorre
    Participant

    I think the problem is that after I run the search, those variables aren’t stored anywhere to access again, they are just in the url. So if I try and append the orderby and order to the end of the url, it doesn’t remember what the previous values were.

    Is there any way I can store the searched parameters for use again in the subsequent sort options?

    Probably cookies but not sure if that’s the right way?

    #92751
    jacorre
    Participant

    The other option I guess is trying to use sessions.

    #92770
    jacorre
    Participant

    I got it! The variables that I defined are available after the search form is processed. So what I did was include those variables within the url and then appended the orderby and order to the end. For example:

    ">Order By Title (ASC)

    Now I just need to get it working as a drop down option!

    #92814
    davidlab.be
    Participant

    Be sure to use the wp rewrite api. Rather easy to use.
    http://codex.wordpress.org/Rewrite_API/add_rewrite_rule

Viewing 6 posts - 1 through 6 (of 6 total)
  • The forum ‘Back End’ is closed to new topics and replies.