Skip to main content
added 518 characters in body
Source Link

I have a custom post type in WordPress with custom meta boxes.

So I need a hierarchal post and also have a custom template set for each of the post (either Type1 or Type2).

This is how my slug looks,

http://example.com/taxonomy/type1 - for the primary post

http://example.com/taxonomy/type1/type2 - for the secondary post

The problem is that the type 2 page is essentially the same as the type1 just with a bit of additional information. And my client plans to have many posts in type1 which will lead to more posts in type2 and this will make managing hard.

I can save all the content I need for type2 posts within the parent type1 using meta boxes. I just need a way to point the URLs to the right data.

So if I access this URL, http://example.com/taxonomy/type1/type2, it will open primary post and load the data for it from a meta box (also has to load another template file). I want this done via php and don't want to load all the content and edit it frontend using javascript.

Update:

Sorry if I was a bit confusing. I already have a custom post type with a metabox that allows me to select a template (and also show additional metaboxes depending on the template).

My slug already has the custom taxonomy I am using (used %name% as the slug in the argument for creating posts.

And my posts slug work fine as long as I choose the right parent post. My question is, instead of creating a custom post (type2) as a child to the type1 post, how can I make wordpress redirect http://example.com/taxonomy/type1/type2 to the type1 post and also get the text of type2 within a php function where I can print out the template for the pages.

Edit

add_filter('query_vars', 'add_type2_var', 0, 1); 

function add_type2_var($vars){ $vars[] = 'type2'; return $vars; }

add_rewrite_rule('/?apk/(.[^/])/(.[^/])/(.*)$',"/wp/apk/$1/$2?type2=$3",'top');

I have added this code to my theme and did not modify .htaccess. The type2 var shows up correctly when I use a child post url or if I add numbers at the end. I set hierarchical to false for the custom post type and the link still shows 404. Is there a way for me to bypass the 404? My guess is that I am trying to get the url using the single_template filter. But I should validate it somewhere before wordpress gives a 404.

I have a custom post type in WordPress with custom meta boxes.

So I need a hierarchal post and also have a custom template set for each of the post (either Type1 or Type2).

This is how my slug looks,

http://example.com/taxonomy/type1 - for the primary post

http://example.com/taxonomy/type1/type2 - for the secondary post

The problem is that the type 2 page is essentially the same as the type1 just with a bit of additional information. And my client plans to have many posts in type1 which will lead to more posts in type2 and this will make managing hard.

I can save all the content I need for type2 posts within the parent type1 using meta boxes. I just need a way to point the URLs to the right data.

So if I access this URL, http://example.com/taxonomy/type1/type2, it will open primary post and load the data for it from a meta box (also has to load another template file). I want this done via php and don't want to load all the content and edit it frontend using javascript.

Update:

Sorry if I was a bit confusing. I already have a custom post type with a metabox that allows me to select a template (and also show additional metaboxes depending on the template).

My slug already has the custom taxonomy I am using (used %name% as the slug in the argument for creating posts.

And my posts slug work fine as long as I choose the right parent post. My question is, instead of creating a custom post (type2) as a child to the type1 post, how can I make wordpress redirect http://example.com/taxonomy/type1/type2 to the type1 post and also get the text of type2 within a php function where I can print out the template for the pages.

I have a custom post type in WordPress with custom meta boxes.

So I need a hierarchal post and also have a custom template set for each of the post (either Type1 or Type2).

This is how my slug looks,

http://example.com/taxonomy/type1 - for the primary post

http://example.com/taxonomy/type1/type2 - for the secondary post

The problem is that the type 2 page is essentially the same as the type1 just with a bit of additional information. And my client plans to have many posts in type1 which will lead to more posts in type2 and this will make managing hard.

I can save all the content I need for type2 posts within the parent type1 using meta boxes. I just need a way to point the URLs to the right data.

So if I access this URL, http://example.com/taxonomy/type1/type2, it will open primary post and load the data for it from a meta box (also has to load another template file). I want this done via php and don't want to load all the content and edit it frontend using javascript.

Update:

Sorry if I was a bit confusing. I already have a custom post type with a metabox that allows me to select a template (and also show additional metaboxes depending on the template).

My slug already has the custom taxonomy I am using (used %name% as the slug in the argument for creating posts.

And my posts slug work fine as long as I choose the right parent post. My question is, instead of creating a custom post (type2) as a child to the type1 post, how can I make wordpress redirect http://example.com/taxonomy/type1/type2 to the type1 post and also get the text of type2 within a php function where I can print out the template for the pages.

Edit

add_filter('query_vars', 'add_type2_var', 0, 1); 

function add_type2_var($vars){ $vars[] = 'type2'; return $vars; }

add_rewrite_rule('/?apk/(.[^/])/(.[^/])/(.*)$',"/wp/apk/$1/$2?type2=$3",'top');

I have added this code to my theme and did not modify .htaccess. The type2 var shows up correctly when I use a child post url or if I add numbers at the end. I set hierarchical to false for the custom post type and the link still shows 404. Is there a way for me to bypass the 404? My guess is that I am trying to get the url using the single_template filter. But I should validate it somewhere before wordpress gives a 404.

added 674 characters in body
Source Link

I have a custom post type in WordPress with custom meta boxes.

So I need a hierarchal post and also have a custom template set for each of the post (either Type1 or Type2).

This is how my slug looks,

http://example.com/taxonomy/type1 - for the primary post

http://example.com/taxonomy/type1/type2 - for the secondary post

The problem is that the type 2 page is essentially the same as the type1 just with a bit of additional information. And my client plans to have many posts in type1 which will lead to more posts in type2 and this will make managing hard.

I can save all the content I need for type2 posts within the parent type1 using meta boxes. I just need a way to point the URLs to the right data.

So if I access this URL, http://example.com/taxonomy/type1/type2, it will open primary post and load the data for it from a meta box (also has to load another template file). I want this done via php and don't want to load all the content and edit it frontend using javascript.

Update:

Sorry if I was a bit confusing. I already have a custom post type with a metabox that allows me to select a template (and also show additional metaboxes depending on the template).

My slug already has the custom taxonomy I am using (used %name% as the slug in the argument for creating posts.

And my posts slug work fine as long as I choose the right parent post. My question is, instead of creating a custom post (type2) as a child to the type1 post, how can I make wordpress redirect http://example.com/taxonomy/type1/type2 to the type1 post and also get the text of type2 within a php function where I can print out the template for the pages.

I have a custom post type in WordPress with custom meta boxes.

So I need a hierarchal post and also have a custom template set for each of the post (either Type1 or Type2).

This is how my slug looks,

http://example.com/taxonomy/type1 - for the primary post

http://example.com/taxonomy/type1/type2 - for the secondary post

The problem is that the type 2 page is essentially the same as the type1 just with a bit of additional information. And my client plans to have many posts in type1 which will lead to more posts in type2 and this will make managing hard.

I can save all the content I need for type2 posts within the parent type1 using meta boxes. I just need a way to point the URLs to the right data.

So if I access this URL, http://example.com/taxonomy/type1/type2, it will open primary post and load the data for it from a meta box (also has to load another template file). I want this done via php and don't want to load all the content and edit it frontend using javascript.

I have a custom post type in WordPress with custom meta boxes.

So I need a hierarchal post and also have a custom template set for each of the post (either Type1 or Type2).

This is how my slug looks,

http://example.com/taxonomy/type1 - for the primary post

http://example.com/taxonomy/type1/type2 - for the secondary post

The problem is that the type 2 page is essentially the same as the type1 just with a bit of additional information. And my client plans to have many posts in type1 which will lead to more posts in type2 and this will make managing hard.

I can save all the content I need for type2 posts within the parent type1 using meta boxes. I just need a way to point the URLs to the right data.

So if I access this URL, http://example.com/taxonomy/type1/type2, it will open primary post and load the data for it from a meta box (also has to load another template file). I want this done via php and don't want to load all the content and edit it frontend using javascript.

Update:

Sorry if I was a bit confusing. I already have a custom post type with a metabox that allows me to select a template (and also show additional metaboxes depending on the template).

My slug already has the custom taxonomy I am using (used %name% as the slug in the argument for creating posts.

And my posts slug work fine as long as I choose the right parent post. My question is, instead of creating a custom post (type2) as a child to the type1 post, how can I make wordpress redirect http://example.com/taxonomy/type1/type2 to the type1 post and also get the text of type2 within a php function where I can print out the template for the pages.

Source Link

Get slug to point to different content of the same post

I have a custom post type in WordPress with custom meta boxes.

So I need a hierarchal post and also have a custom template set for each of the post (either Type1 or Type2).

This is how my slug looks,

http://example.com/taxonomy/type1 - for the primary post

http://example.com/taxonomy/type1/type2 - for the secondary post

The problem is that the type 2 page is essentially the same as the type1 just with a bit of additional information. And my client plans to have many posts in type1 which will lead to more posts in type2 and this will make managing hard.

I can save all the content I need for type2 posts within the parent type1 using meta boxes. I just need a way to point the URLs to the right data.

So if I access this URL, http://example.com/taxonomy/type1/type2, it will open primary post and load the data for it from a meta box (also has to load another template file). I want this done via php and don't want to load all the content and edit it frontend using javascript.