Wordpress Page - I need to GET variables - wordpress

I am not a wordpress guy and a client needs me to modify some pages. Someone else has created the entire site in wordpress.
I am having trouble with a query string that contains variables.
wordpresssite.com/pages-using-template/?variable=something
This causes the page to get thrown to the default 404 for the site..
Any suggestions on which file i need to fix this in and how to do it?
Thanks

wordpresssite.com/pages-using-template/?variable=something
That's giving you a 404 error, probably because you're trying to add the query string variable to the home page of the site. There's no "file" that fixes this - WordPress is dynamic. the .htaccess rules handle the URL rewrites ("pretty permalinks")
So I guess you need to give more information on what it is you're trying to do. There's not going to really be a way to "fix" the URL without breaking the rest of the site (it's possible, but I'm betting that whatever it is you're trying to do requires a much simpler solution).
What query string are you trying to add in? For what reason?
For example, I recently did a WordPress site from someone who needed a directory on one page of the site, that had a custom search from in it. I created a function that would $_GET the URL of the page and add the search query to it, and then return the end user to the page with the results there.
You also have to be careful about the $_GET in your functions - you want to be sure they're protected against injection attacks by using $wpdb->escape($_GET['xxx']).

Related

Wordpress loading post based on query (URL) automatically

I am sure I am going to sound the newb here, but this is something I have not noticed up till now with all the work I have ever done with WordPress.
Today I noticed that if I even if I only enter a portion of a post's name in the URL query, WordPress will try to find and show a matching post. For example, if I go to:
example.com/about
It will take me to:
example.com/about-us (which is the correct post name).
Another example, is if I go to:
example.com/priv
WordPress takes me:
example.com/privacy-policy
Did WordPress always do this? If so, then I never noticed (and will sound dumb asking this). I assumed it would give me 404 if the post name in the query was not found.
Cheers

wordpress delivers wrong page

Currently running WordPress 4.9.5 using the Divi theme with Permalinks set to use Post name, I can enter a url (page title/name) that does not exist on the site and WordPress will deliver a page that has the “filename” part of the url somewhere in the title/name of the page it delivers but is different than the actual url.
For example, if you go to http://space.nss.org/renew/
Instead of getting a 404, WordPress delivers the page http://space.nss.org/renewable-energy-partnership/
What on Earth is WordPress thinking?
What can I do to identify the exact nature of the problem and fix it?
Note that this behavior is not universal as I can enter bad urls (like space.nss.org/armstrong/) and do get the expected error page.
Thanks in advance, Jim.
NOTE: The url referenced above (space.nss.org/renew/) has now been fixed so its original behavior is no longer exhibited.
With respect to my problem, it turns out that Wordpress is just trying to help by assuming that humans do not know how to type.
When I type "space.nss.org/renew/" and Wordpress doesn't find an exact match, it looks for anything it can find containing the string "renew"
and delivers what it considers to be the best match as a way of avoiding delivering a 404 page to the visitor.
This feature can be turned off but there are consequences in that the 'redirect_canonical' is also responsible for resolving domain name issues (like www.domain.com vs domain.com). For reference, see https://codex.wordpress.org/Function_Reference/redirect_canonical
Following are references on the subject I found once I knew what I was looking for.
[https://wordpress.stackexchange.com/questions/3326/301-redirect-instead-of-404-when-url-is-a-prefix-of-a-post-or-page-name]
2
[https://serverfault.com/questions/776310/how-to-disable-the-automatic-redirection-in-wordpress-htaccess-file]
3
[http://biostall.com/prevent-wordpress-redirecting-to-nearest-matching-url/]
Looking at the network log it appears there is a 301 redirect placed on /renew to go to /renewable-energy-partnership
As a solution you could remove the redirect so that it goes to the 404 page instead.

Why does WordPress allow multiple page-slugs in url without triggering 404?

The title is pretty self explanatory, but I'm trying to figure out why WordPress allows this or if it's a setting in .htaccess perhaps, but here's the example:
I have a page, lets say a "Contact" page with the slug of "contact-us".
I go to http://example.com/contact-us/ -- everything works normally
I go to http://example.com/contact-us/contact-us/contact-us/contact-us/contact-us/contact-us (I could do this a million times) and it does NOT trigger a 404 error!
Why is this? If I enter a random string of numbers, it instantly triggers 404.php, but just repeating the page-slug does not trigger a 404.
I would like the page-slug to not be able to be repeated over and over again and trigger a 404 if it even gets repeated once.
Has anyone else experienced this issue? Is it possibly a canonical link issue or a "nofollow". I just don't understand why WordPress is not seeing this as 404 material.
Thanks in advance for any replies, suggestions, and help.
I have found a way to solve my own problem. Today I noticed that I was running two WordPress builds on the same server but one went to 404 while the other would just go back to the page. Now I knew it was a theme specific issue.
The answer is really simple actually, it was a permalink issue. In order for me to get the behavior I was looking for, I had to select "Post Name" as my permalink settings.
I previously had a custom string of options for a different style display using "Custom Structure", which I'm assuming had the "failsafe" in it.
I'm willing to switch out the extra permalink styling options in favor of the 404.
Although, those that opt to use a custom permalink structure should see if this happens to you.

Set the permalink to any domain in Wordpress

Is this possible to achieve without too much effort or a plugin? It's simply to instantly redirect to a site I've made in my portfolio if the post doesn't have any content.
Note that I don't want a script in the actual post to redirect since I only use Wordpress as the backend and fetch all the data to be used by a JavaScript backbone app.
EDIT : Added some extra info in a comment
Short Answer: No. You cannot set your Post Permalink to an external asset without directly editing the database.
Long Answer: First off, you need to understand the purpose of the Permalink. It isn't just an arbitrary link to somewhere. It's reserved specifically for storing where that specific post lives within the context of your Wordpress installation.
Your post doesn't live on example.com. It has its own ID, and Wordpress has a specific spot set aside for it where it can be seen on YOUR domain. Leave it as such.
Instead, what you should be doing is employing the tools Wordpress gives you to achieve what you want. A Plugin doesn't exist for what you want because - quite frankly - it's a fairly trivial task when approached CORRECTLY and doesn't warrant the use of an external resource.
So what's the correct way?
Use a Custom Field. Name your Custom Field something like 'externalHref' and fill that in with your link to the website you want to point to in case there's no post content.
Then in whatever templates you're using to generate your posts, just check either for the existence of your Custom Field called 'externalHref' or check for the non-existence of Post Content. In either case, instead of generating a link using The Permalink you can simply build a link that points to wherever you need.

Problems with Drupal 7's clean URLs

I've looked around and I couldn't find an answer to my question so here it is.
Clean URLs are enabled on my Drupal 7 website and are "working" in the sense that I can access the About Us page with www.mysite.com/about-us and with www.mysite.com/node/12.
However, usually with Wordpress and the get_permalink() function, every menu/links like ?p=12 get redirected/rewritten to /about-us. But with Drupal, my menu links are in the form node/12 , and when I click on a link I get the page /node/12, not /about-us.
Any idea how I can get the rewriting/re-routing done automatically?
Thanks!
Your best bet would be the Global redirect module. The first of its many functions is:
Checks the current URL for an alias and does a 301 redirect to it if it is not being used.
I've used it in just about every Drupal site I've ever made and it works well.

Resources