Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Post not found error 404 #79

Open
luizaraujoofficial opened this issue Sep 28, 2017 · 4 comments
Open

Post not found error 404 #79

luizaraujoofficial opened this issue Sep 28, 2017 · 4 comments

Comments

@luizaraujoofficial
Copy link

Hello, I am using the plugin, it creates perfectly the url I want, but when opening the url of the post shows me page not found.

Is there a solution or something I should configure?

@luizaraujoofficial
Copy link
Author

Complementing, I noticed that the problem is only when I try to use a taxonomy that has a subcategory, some solution?

@romainhe
Copy link

Any news from that @torounit ?

@briandesp
Copy link

briandesp commented Aug 27, 2018

I am seeing this same exact issue when using subcategories. In my case sub taxonomies (custom taxonomy tree)

@enkodellc
Copy link

I have a solution that some others might want to investigate and or if a more knowledgeable wordpress coder wants to share their ideas on my script. I took the approach of writing a 404 handler in an attempt to fix the issue that the hierarchical taxonomies present below is my exact code. All my taxonomies begin with pdm_ and I needed to do some extra work for WPML / multi language slugs. I also have several custom post types. It is not clean but it works.

   function wpd_do_stuff_on_404(){
    if( is_404() ){

	  $lang = '';
	  switch(strtolower(explode('/', $_SERVER['REQUEST_URI'])[1])) {
		case "en" : $lang = 'en'; break;
		case "es" : $lang = 'es'; break;
		case "de" : $lang = 'de'; break;
		case "fr" : $lang = 'fr'; break;
		case "zh-hans" : $lang = 'zh-hans'; break;	
	  }

         global $wp_query;
	  global $wp;
	  $permalink = $wp->request;
	  $urlParts = explode('/', $permalink);
	  $ptType = 'post';

       if (count($urlParts) > 1) {
	  switch(strtolower($urlParts[0])) {
	  case "stay-dive" :
	  case "hotel" :
	  case "hotels" :
		$ptType = "pdm_hotel";
	   break;
	  case "excursion-category" :
	  case "excursion" :
	  case "excursions" :
		$ptType = "pdm_excursion";
	   break;
	  case "dive-site" :
		$ptType = "pdm_dive_site";		
	   break;
	  case "dive-center" :
	  case "dive-centers" :
		$ptType = "pdm_dive_center";
	   break;
	  case "diving-course" :
	  case "diving-courses" :
		$ptType = "pdm_dive_course";
	   break;
  	  case "product" :
  	  case "products" :
		$ptType = "pdm_product";
	   break;
	 }

         if ($ptType) {

	  //WPML Get CPT translated id
             $my_post = get_page_by_path($urlParts[count($urlParts) -1], OBJECT, $ptType);    
             $get_translated_id = apply_filters('wpml_object_id', $my_post->ID, $ptType );
	      if ($get_translated_id && ($get_translated_id != $my_post->ID)) {
		 $my_post = get_post($get_translated_id);
	      }

           // Set the wp_query for the real post 
             if( $my_post) {
       		 $post = get_post($my_post->ID);
        	 $wp_query->queried_object = $my_post;
        	 $wp_query->is_single = true;
        	 $wp_query->is_404 = false;
        	 $wp_query->queried_object_id = $my_post->ID;
        	 $wp_query->post_count = 1;
        	 $wp_query->current_post=-1;
 		 $wp_query->suppress_filters = false;
        	 $wp_query->posts = array($my_post);
             }
           }
         }
      }
}

add_action( 'template_redirect', 'wpd_do_stuff_on_404' );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants