Treehouse: Grow your CSS skills. Land your dream job.

Can you append values to the end of a url?

  • # December 14, 2011 at 12:07 pm

    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.

    # December 14, 2011 at 2:54 pm

    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 :-)

    # December 14, 2011 at 3:23 pm

    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?

    # December 14, 2011 at 3:38 pm

    The other option I guess is trying to use sessions.

    # December 14, 2011 at 8:41 pm

    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!

    # December 15, 2011 at 7:17 am

    Be sure to use the wp rewrite api. Rather easy to use.

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.