- This topic is empty.
December 14, 2011 at 12:07 pm #35646
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:
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 #92746thebreiflabbMember
Hello, I haven’t really used wordpress much, but I know some PHP. Top of my head I figured this should work:
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 #92748
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 #92751
The other option I guess is trying to use sessions.December 14, 2011 at 8:41 pm #92770
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:
Now I just need to get it working as a drop down option!December 15, 2011 at 7:17 am #92814davidlab.beParticipant
Be sure to use the wp rewrite api. Rather easy to use.
- The forum ‘Back End’ is closed to new topics and replies.