google-code-export / wordpress-custom-content-type-manager

Automatically exported from code.google.com/p/wordpress-custom-content-type-manager
2 stars 1 forks source link

CCTM overrides the set post type in archive pages #493

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
1- Define a post type "movie" with archive and Category enabled.
2- Define a post type "book" with archive and Category enabled.
3- Create a category "sci-fi"
4- Create a few movies in category "sci-fi"
5- Create a few books in category "sci-fi"
6- browse to [site_url]/category/sci-fi. You'll get posts from both post types. 
So far so good.
7- browse to [site_url]/index.php?post_type=book&category_name=sci-fi . 
Depending on your permalink structure you'll most likely get redirected to 
[site_url]/category/sci-fi/?post_type=book but you still get posts from both 
post types which is not the intended behaviour.

I haven't tested it as much but I believe the same applies to month/year 
archives as well.

Obviously I was not trying to access the site through index.php, that was just 
simplifying the situation. I was trying to add new re-write rules to support 
[site_utl]/[post_type]/category/[category_name]/ which kept returning with all 
post types within the category. When I output $wp_query 
(var_dump), I can see post_type is an array containing all the defined post 
types which have "Category" enabled and it ignores/overrides the set post_type 
param.

As a test I commented out line 2577 of includes\CCTM.php ( 
$search_me_post_types[] = $post_type; ) and that solved the problem.

I understand it's there to include all posts in archive pages but maybe it 
needs to check if post_type is already set and leave it alone if it is.

*SYSTEM INFO* 
------------------------ 
Plugin Version: 0.9.7.4-pl
WordPress Version: 3.5.1
PHP Version: 5.2.17
MySQL Version: 5.1.53-log
Server OS: Linux

Original issue reported on code.google.com by soro...@thedevguys.com on 14 May 2013 at 10:57

GoogleCodeExporter commented 9 years ago
I reported the line which I commented out to temporarily fix the problem wrong. 
It should be line 2581 ( $query['post_type'] = $search_me_post_types; )

Original comment by soro...@thedevguys.com on 14 May 2013 at 11:04

GoogleCodeExporter commented 9 years ago
As a better solution I modified the conditions on lines 2546 and 2566 to alter 
$query['post_type'] only if it is not set. The file is attached.

Original comment by soro...@thedevguys.com on 14 May 2013 at 11:13

Attachments:

GoogleCodeExporter commented 9 years ago
Thanks for the thorough report and the solution.  I've added this to the code.  

Committed revision 713205.

I must say that I loathe WP more and more and more... watching how it handles 
URLs and queries is like watching a priest molest little kids.

Original comment by ever...@fireproofsocks.com on 14 May 2013 at 11:50

GoogleCodeExporter commented 9 years ago
I just realized the same problem exists for the tag archive pages as well, so I 
applied the same fix for line 2589 of CCTM.php.

*SYSTEM INFO* 
------------------------ 
Plugin Version: 0.9.7.6-pl
WordPress Version: 3.5.1
PHP Version: 5.2.17
MySQL Version: 5.1.53-log
Server OS: Linux

Fix attached.

Original comment by soro...@thedevguys.com on 18 Jun 2013 at 5:51

Attachments:

GoogleCodeExporter commented 9 years ago
Thanks for the fix.  Added.

Committed revision 728022.

Original comment by ever...@fireproofsocks.com on 18 Jun 2013 at 5:58