0

I'm using WPML installation with the languages in different directories. But I'm trying to pass some _$GET parameters to the url and I'm getting the 404 error.

I'm passing the _$GET parameters with a link. Just like this:

$link_aqui_se_sirve = get_permalink( get_page_by_path('donde') );
$taxonomia_estados = get_terms('estados');

foreach ( $taxonomia_estados as $tax ) :
     $nombre_estado = $tax->name;
     $link = $link_aqui_se_sirve.'?'.$establecimientos_cpt_name.'='.$tax->slug;
     <a href="<?php echo $link; ?>"><?php echo $some_name; ?></a>
endforeach;

I'm getting correctly the url, example: site.com/es/donde/?establecimiento=oaxaca but I get the 404 error.

I've used this way before, in other site (no multilingual) and works good. Any idea to solve it? Thanks!

  • 1
    I think the issue stems from using your CPT name as a GET param. WordPress creates query vars for custom post types. Essentially this request is telling WordPress to get the establecimientos with the name or ID oaxaca. Unless you have a post that happens to have a slug that is the same as that tax slug this will give you a 404. Does this work if you use a different name for your GET param? – Mathew Tinsley Jun 16 '15 at 15:57
  • Thanks a lot @mtinsley, you are right. I didn't know about the query vars for cpt. If I change my GET param to different name, all works correctly. Could you post it like an answer to give you the bounty, or there is a way to give you manually in the comment? Thank you very much, you save me a lot time! – Jabel Márquez Jun 17 '15 at 17:27
2
+50

The problem your GET param is using the same name as the query var for your custom post type.

$link = $link_aqui_se_sirve.'?'.$establecimientos_cpt_name.'='.$tax->slug;

With that URL, WordPress is expecting the value of the $establecimientos_cpt_name parameter to be a post slug. Instead you are giving it a taxonomy slug. This will give you a 404 unless you have a post that happens to have the same slug as your taxonomy.

If you are setting this parameter for your own purposes, you should choose a name that does not collide with WordPress' internal request processing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.