WordPress.org

Ready to get started?Download WordPress

Forums

How to pass variables in my url whilst using 'pretty' permalinks (14 posts)

  1. nicolaelvin
    Member
    Posted 2 years ago #

    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?

  2. IshaanRawat
    Member
    Posted 2 years ago #

  3. nicolaelvin
    Member
    Posted 2 years ago #

    Preferably the first option

  4. IshaanRawat
    Member
    Posted 2 years ago #

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

    I hope it helps...
    Happy Coding
    [signature moderated]

  5. nicolaelvin
    Member
    Posted 2 years ago #

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

  6. IshaanRawat
    Member
    Posted 2 years ago #

    yes

  7. nicolaelvin
    Member
    Posted 2 years ago #

    That is already my structure

  8. nicolaelvin
    Member
    Posted 2 years ago #

    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]

  9. ClaytonJames
    Member
    Posted 2 years ago #

    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.

  10. nicolaelvin
    Member
    Posted 2 years ago #

    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.

  11. ClaytonJames
    Member
    Posted 2 years ago #

    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?

  12. nicolaelvin
    Member
    Posted 2 years ago #

    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.

  13. nicolaelvin
    Member
    Posted 2 years ago #

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

  14. nicolaelvin
    Member
    Posted 2 years ago #

    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!

Topic Closed

This topic has been closed to new replies.

About this Topic