Support » Fixing WordPress » How to pass variables in my url whilst using 'pretty' permalinks

  • I have realised that I cannot just add them in to the <a> href like href=”mysite/mypage/?name=$image_name.

    So I have used add_query_arg( “name”, $imageName,’http://mysite.co.uk/?p=334′), however that doesn’t work either because wordpress rewrites the p=334 bit to the pretty permalink so the variables don’t get passed, and I get a page not found error, since it changes the href to http://mysite.co.uk/my-page/?name=$image_name.

    Tearing my hair out, does anyone have a solution?

Viewing 13 replies - 1 through 13 (of 13 total)
  • Preferably the first option

    Then…..
    1>Go to Permalinks…
    2>Then Select CUstom Structure..
    ad in then write “/%postname%/”

    I hope it helps…
    Happy Coding
    [signature moderated]

    Thanks Ishaan, but will that enable me to pass parameters in my url?

    yes

    That is already my structure

    can anyone else help please? It’s a straightforward questions which 3 hours of searching google and trying out code has no been able to solve!

    [please do not bump – adding comments like this does not help to get any suggestions]

    There has been a substantial amount of conversation on the subject here in the forums in the past. I know you’ve searched, but maybe limiting the returns to just the forum discussion will give you a push in the right direction. site:wordpress.org/support pass variables in url

    Here is a list of those topics that have already been marked resolved, increasing the chance of finding a solution that might work for your situation. site:wordpress.org/support pass variables in url resolved

    I know it’s not much to offer, and you’ve already looked, but maybe something will pop out at you in the narrowed search result.

    Ok thanks for your help. I think I’ll have to start a new thread because in none of the threads does anyone mention the issue of the actual link changing to how the permalink settings are, when it changes this is when I get a not found page.

    in none of the threads does anyone mention the issue of the actual link changing to how the permalink settings are, when it changes

    That’s a bit confusing. Just to be clear, are you getting any 404’s after you change the permalink structure from the WordPress dashboard settings? Or does that seem to work just fine, and you only get the 404’s when passing custom variables in the url?

    I suppose it is confusing, sorry, I don’t think I am thinking clearly any more.

    If I change the permalink back to the defaults, so mywebsite.com/?p=123 and then use add_query_arg( "name", $imageName,'http://mywebsite.com/?p=123) the link it outputs actually works, it takes me to the correct page.

    However, my permalinks are set up to show the post or page name, so the page I want to get to is mywebsite.com/buying-options. This is the cause of the problem, since if if use the following with my custom permalinks:

    add_query_arg( "name", $imageName,'http://mywebsite.com/?=p123),

    it outputs correctly (http://mywebsite.com/?p=123&name=myimagename), but on clicking that link, it redirects to http://mywebsite.com/buying-options/?name=myimagename). This link doesn’t work, it comes back with page not found.

    so yes, I only get the 404s when passing the variables to the url

    the issue has been solved by a friend of mine who suggested changing the name of my ‘name’ variable in case it was reserved by wordpress. I did and it works now!

    So for anyone else, make sure you aren’t using a common name like..name!

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘How to pass variables in my url whilst using 'pretty' permalinks’ is closed to new replies.