[wp-trac] [WordPress Trac] #15943: Custom Post Type not being set on WPMS with Custom Permalinks

WordPress Trac wp-trac at lists.automattic.com
Wed Dec 22 19:39:17 UTC 2010


#15943: Custom Post Type not being set on WPMS with Custom Permalinks
--------------------------+-----------------------------
 Reporter:  sterlo        |       Owner:
     Type:  defect (bug)  |      Status:  reopened
 Priority:  normal        |   Milestone:  Future Release
Component:  Multisite     |     Version:  3.0.3
 Severity:  normal        |  Resolution:
 Keywords:                |
--------------------------+-----------------------------

Comment (by sterlo):

 Disclaimer: This is pretty verbose, sorry about that. It also includes a
 link to a gist that has a test plugin in it. Feel free to use your own
 code so we have more than one kind of testing.

 My testing produced this really lame 'solution'. I was able to get this to
 work locally on apache2 for MS 3.0.3 and Standard (from
 wordpress.org/latest.zip) AND 3.1-beta2-17056 (standard setup)

 Steps to reproduce:

  1. Install a new site (MS or not - does not matter).
  2. Install this plugin (it's one file): https://gist.github.com/751946
  3. Add a new 'product'
  4. After publishing the product - click the view post button:
  [[BR]]http://wordpress-test.local/?acme_product=test-product
  [[BR]]You should see this as output for $wp_query (post_type is set):
 {{{
 WP_Query Object
 (
     [query_vars] => Array
         (
             [acme_product] => test-product
             [post_type] => acme_product
             [name] => test-product
             [error] =>
             [m] => 0
             [p] => 0
             [post_parent] =>
             [subpost] =>
             [subpost_id] =>
             [attachment] =>
             [attachment_id] => 0
             [static] =>
             [pagename] =>
             [page_id] => 0
             [second] =>
             [minute] =>
             [hour] =>
             [day] => 0
             [monthnum] => 0
             [year] => 0
             [w] => 0
             [category_name] =>
             [tag] =>
             [cat] =>
             [tag_id] =>
             [author_name] =>
             [feed] =>
             [tb] =>
             [paged] => 0
             [comments_popup] =>
             [meta_key] =>
             [meta_value] =>
             [preview] =>
             [s] =>
             [sentence] =>
             [fields] =>
             [category__in] => Array
                 (
                 )

             [category__not_in] => Array
                 (
                 )

             [category__and] => Array
                 (
                 )

             [post__in] => Array
                 (
                 )

             [post__not_in] => Array
                 (
                 )

             [tag__in] => Array
                 (
                 )

             [tag__not_in] => Array
                 (
                 )

             [tag__and] => Array
                 (
                 )

             [tag_slug__in] => Array
                 (
                 )

             [tag_slug__and] => Array
                 (
                 )

             [ignore_sticky_posts] =>
             [suppress_filters] =>
             [cache_results] => 1
             [update_post_term_cache] => 1
             [update_post_meta_cache] => 1
             [posts_per_page] => 10
             [nopaging] =>
             [comments_per_page] => 50
             [no_found_rows] =>
             [order] => DESC
             [orderby] => wp_posts.post_date DESC
         )

     [tax_query] => WP_Tax_Query Object
         (
             [queries] => Array
                 (
                 )

             [relation] => AND
         )

     [post_count] => 1
     [current_post] => -1
     [in_the_loop] =>
     [comment_count] => 0
     [current_comment] => -1
     [found_posts] => 0
     [max_num_pages] => 0
     [max_num_comment_pages] => 0
     [is_single] => 1
     [is_preview] =>
     [is_page] =>
     [is_archive] =>
     [is_date] =>
     [is_year] =>
     [is_month] =>
     [is_day] =>
     [is_time] =>
     [is_author] =>
     [is_category] =>
     [is_tag] =>
     [is_tax] =>
     [is_search] =>
     [is_feed] =>
     [is_comment_feed] =>
     [is_trackback] =>
     [is_home] =>
     [is_404] =>
     [is_comments_popup] =>
     [is_paged] =>
     [is_admin] =>
     [is_attachment] =>
     [is_singular] => 1
     [is_robots] =>
     [is_posts_page] =>
     [is_post_type_archive] =>
     [query] => Array
         (
             [acme_product] => test-product
             [post_type] => acme_product
             [name] => test-product
         )

     [request] =>  SELECT   wp_posts.* FROM wp_posts  WHERE 1=1  AND
 wp_posts.post_name = 'test-product' AND wp_posts.post_type =
 'acme_product'  ORDER BY wp_posts.post_date DESC
     [posts] => Array
         (
             [0] => stdClass Object
                 (
                     [ID] => 4
                     [post_author] => 1
                     [post_date] => 2010-12-22 19:15:02
                     [post_date_gmt] => 2010-12-22 19:15:02
                     [post_content] => Test content.
                     [post_title] => Test Product
                     [post_excerpt] =>
                     [post_status] => publish
                     [comment_status] => open
                     [ping_status] => open
                     [post_password] =>
                     [post_name] => test-product
                     [to_ping] =>
                     [pinged] =>
                     [post_modified] => 2010-12-22 19:15:02
                     [post_modified_gmt] => 2010-12-22 19:15:02
                     [post_content_filtered] =>
                     [post_parent] => 0
                     [guid] => http://wordpress-
 test.local/?post_type=acme_product&p=4
                     [menu_order] => 0
                     [post_type] => acme_product
                     [post_mime_type] =>
                     [comment_count] => 0
                     [ancestors] => Array
                         (
                         )

                     [filter] => raw
                 )

         )

     [post] => stdClass Object
         (
             [ID] => 4
             [post_author] => 1
             [post_date] => 2010-12-22 19:15:02
             [post_date_gmt] => 2010-12-22 19:15:02
             [post_content] => Test content.
             [post_title] => Test Product
             [post_excerpt] =>
             [post_status] => publish
             [comment_status] => open
             [ping_status] => open
             [post_password] =>
             [post_name] => test-product
             [to_ping] =>
             [pinged] =>
             [post_modified] => 2010-12-22 19:15:02
             [post_modified_gmt] => 2010-12-22 19:15:02
             [post_content_filtered] =>
             [post_parent] => 0
             [guid] => http://wordpress-
 test.local/?post_type=acme_product&p=4
             [menu_order] => 0
             [post_type] => acme_product
             [post_mime_type] =>
             [comment_count] => 0
             [ancestors] => Array
                 (
                 )

             [filter] => raw
         )

 )
 }}}
  5. Now go turn on custom permalinks, '/%category%/%postname%/', hit save.
  6. Then it asks to do this: Add to your .htaccess file:
 {{{
 <IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteBase /
 RewriteRule ^index\.php$ - [L]
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule . /index.php [L]
 </IfModule>
 }}}
  6. Then I view the post at:
  [[BR]]http://wordpress-test.local/acme_product/test-product/
  7. You should now see this as output for $wp_query (post_type is not
 set):
 {{{
 WP_Query Object
 (
     [query_vars] => Array
         (
             [page] => 0
             [name] => test-product
             [category_name] => acme_product
             [error] =>
             [m] => 0
             [p] => 0
             [post_parent] =>
             [subpost] =>
             [subpost_id] =>
             [attachment] =>
             [attachment_id] => 0
             [static] =>
             [pagename] =>
             [page_id] => 0
             [second] =>
             [minute] =>
             [hour] =>
             [day] => 0
             [monthnum] => 0
             [year] => 0
             [w] => 0
             [tag] =>
             [cat] =>
             [tag_id] =>
             [author_name] =>
             [feed] =>
             [tb] =>
             [paged] => 0
             [comments_popup] =>
             [meta_key] =>
             [meta_value] =>
             [preview] =>
             [s] =>
             [sentence] =>
             [fields] =>
             [category__in] => Array
                 (
                 )

             [category__not_in] => Array
                 (
                 )

             [category__and] => Array
                 (
                 )

             [post__in] => Array
                 (
                 )

             [post__not_in] => Array
                 (
                 )

             [tag__in] => Array
                 (
                 )

             [tag__not_in] => Array
                 (
                 )

             [tag__and] => Array
                 (
                 )

             [tag_slug__in] => Array
                 (
                 )

             [tag_slug__and] => Array
                 (
                 )

             [ignore_sticky_posts] =>
             [suppress_filters] =>
             [cache_results] => 1
             [update_post_term_cache] => 1
             [update_post_meta_cache] => 1
             [post_type] =>
             [posts_per_page] => 10
             [nopaging] =>
             [comments_per_page] => 50
             [no_found_rows] =>
             [order] => DESC
             [orderby] => wp_posts.post_date DESC
         )

     [tax_query] => WP_Tax_Query Object
         (
             [queries] => Array
                 (
                     [0] => Array
                         (
                             [taxonomy] => category
                             [terms] => Array
                                 (
                                     [0] => acme_product
                                 )

                             [include_children] => 1
                             [field] => slug
                             [operator] => IN
                         )

                 )

             [relation] => AND
         )

     [post_count] => 0
     [current_post] => -1
     [in_the_loop] =>
     [comment_count] => 0
     [current_comment] => -1
     [found_posts] => 0
     [max_num_pages] => 0
     [max_num_comment_pages] => 0
     [is_single] =>
     [is_preview] =>
     [is_page] =>
     [is_archive] =>
     [is_date] =>
     [is_year] =>
     [is_month] =>
     [is_day] =>
     [is_time] =>
     [is_author] =>
     [is_category] =>
     [is_tag] =>
     [is_tax] =>
     [is_search] =>
     [is_feed] =>
     [is_comment_feed] =>
     [is_trackback] =>
     [is_home] =>
     [is_404] => 1
     [is_comments_popup] =>
     [is_paged] =>
     [is_admin] =>
     [is_attachment] =>
     [is_singular] =>
     [is_robots] =>
     [is_posts_page] =>
     [is_post_type_archive] =>
     [query] => Array
         (
             [page] =>
             [name] => test-product
             [category_name] => acme_product
         )

     [request] =>  SELECT   wp_posts.* FROM wp_posts  WHERE 1=1  AND
 wp_posts.post_name = 'test-product' AND 0 = 1 AND wp_posts.post_type =
 'post' GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC
     [posts] => Array
         (
         )

 )
 }}}
   You should notice that it's not longer setting the post_type and is
 is_404 = 1.
  9. Now go BACK to the permalink page...don't change anything...just hit
 save again.
  Then view then refresh the post and you should see this from $wp_query
 (post_type is set):
 {{{
 WP_Query Object
 (
     [query_vars] => Array
         (
             [page] => 0
             [acme_product] => test-product
             [post_type] => acme_product
             [name] => test-product
             [error] =>
             [m] => 0
             [p] => 0
             [post_parent] =>
             [subpost] =>
             [subpost_id] =>
             [attachment] =>
             [attachment_id] => 0
             [static] =>
             [pagename] =>
             [page_id] => 0
             [second] =>
             [minute] =>
             [hour] =>
             [day] => 0
             [monthnum] => 0
             [year] => 0
             [w] => 0
             [category_name] =>
             [tag] =>
             [cat] =>
             [tag_id] =>
             [author_name] =>
             [feed] =>
             [tb] =>
             [paged] => 0
             [comments_popup] =>
             [meta_key] =>
             [meta_value] =>
             [preview] =>
             [s] =>
             [sentence] =>
             [fields] =>
             [category__in] => Array
                 (
                 )

             [category__not_in] => Array
                 (
                 )

             [category__and] => Array
                 (
                 )

             [post__in] => Array
                 (
                 )

             [post__not_in] => Array
                 (
                 )

             [tag__in] => Array
                 (
                 )

             [tag__not_in] => Array
                 (
                 )

             [tag__and] => Array
                 (
                 )

             [tag_slug__in] => Array
                 (
                 )

             [tag_slug__and] => Array
                 (
                 )

             [ignore_sticky_posts] =>
             [suppress_filters] =>
             [cache_results] => 1
             [update_post_term_cache] => 1
             [update_post_meta_cache] => 1
             [posts_per_page] => 10
             [nopaging] =>
             [comments_per_page] => 50
             [no_found_rows] =>
             [order] => DESC
             [orderby] => wp_posts.post_date DESC
         )

     [tax_query] => WP_Tax_Query Object
         (
             [queries] => Array
                 (
                 )

             [relation] => AND
         )

     [post_count] => 1
     [current_post] => -1
     [in_the_loop] =>
     [comment_count] => 0
     [current_comment] => -1
     [found_posts] => 0
     [max_num_pages] => 0
     [max_num_comment_pages] => 0
     [is_single] => 1
     [is_preview] =>
     [is_page] =>
     [is_archive] =>
     [is_date] =>
     [is_year] =>
     [is_month] =>
     [is_day] =>
     [is_time] =>
     [is_author] =>
     [is_category] =>
     [is_tag] =>
     [is_tax] =>
     [is_search] =>
     [is_feed] =>
     [is_comment_feed] =>
     [is_trackback] =>
     [is_home] =>
     [is_404] =>
     [is_comments_popup] =>
     [is_paged] =>
     [is_admin] =>
     [is_attachment] =>
     [is_singular] => 1
     [is_robots] =>
     [is_posts_page] =>
     [is_post_type_archive] =>
     [query] => Array
         (
             [page] =>
             [acme_product] => test-product
             [post_type] => acme_product
             [name] => test-product
         )

     [request] =>  SELECT   wp_posts.* FROM wp_posts  WHERE 1=1  AND
 wp_posts.post_name = 'test-product' AND wp_posts.post_type =
 'acme_product'  ORDER BY wp_posts.post_date DESC
     [posts] => Array
         (
             [0] => stdClass Object
                 (
                     [ID] => 4
                     [post_author] => 1
                     [post_date] => 2010-12-22 19:15:02
                     [post_date_gmt] => 2010-12-22 19:15:02
                     [post_content] => Test content.
                     [post_title] => Test Product
                     [post_excerpt] =>
                     [post_status] => publish
                     [comment_status] => open
                     [ping_status] => open
                     [post_password] =>
                     [post_name] => test-product
                     [to_ping] =>
                     [pinged] =>
                     [post_modified] => 2010-12-22 19:15:02
                     [post_modified_gmt] => 2010-12-22 19:15:02
                     [post_content_filtered] =>
                     [post_parent] => 0
                     [guid] => http://wordpress-
 test.local/?post_type=acme_product&p=4
                     [menu_order] => 0
                     [post_type] => acme_product
                     [post_mime_type] =>
                     [comment_count] => 0
                     [ancestors] => Array
                         (
                         )

                     [filter] => raw
                 )

         )

     [post] => stdClass Object
         (
             [ID] => 4
             [post_author] => 1
             [post_date] => 2010-12-22 19:15:02
             [post_date_gmt] => 2010-12-22 19:15:02
             [post_content] => Test content.
             [post_title] => Test Product
             [post_excerpt] =>
             [post_status] => publish
             [comment_status] => open
             [ping_status] => open
             [post_password] =>
             [post_name] => test-product
             [to_ping] =>
             [pinged] =>
             [post_modified] => 2010-12-22 19:15:02
             [post_modified_gmt] => 2010-12-22 19:15:02
             [post_content_filtered] =>
             [post_parent] => 0
             [guid] => http://wordpress-
 test.local/?post_type=acme_product&p=4
             [menu_order] => 0
             [post_type] => acme_product
             [post_mime_type] =>
             [comment_count] => 0
             [ancestors] => Array
                 (
                 )

             [filter] => raw
         )

     [queried_object] => stdClass Object
         (
             [ID] => 4
             [post_author] => 1
             [post_date] => 2010-12-22 19:15:02
             [post_date_gmt] => 2010-12-22 19:15:02
             [post_content] => Test content.
             [post_title] => Test Product
             [post_excerpt] =>
             [post_status] => publish
             [comment_status] => open
             [ping_status] => open
             [post_password] =>
             [post_name] => test-product
             [to_ping] =>
             [pinged] =>
             [post_modified] => 2010-12-22 19:15:02
             [post_modified_gmt] => 2010-12-22 19:15:02
             [post_content_filtered] =>
             [post_parent] => 0
             [guid] => http://wordpress-
 test.local/?post_type=acme_product&p=4
             [menu_order] => 0
             [post_type] => acme_product
             [post_mime_type] =>
             [comment_count] => 0
             [ancestors] => Array
                 (
                 )

             [filter] => raw
         )

     [queried_object_id] => 4
 )
 }}}

 Now I should mention that all of my sites in production (3.0.3 from
 latest.zip) have custom permalinks...
 [[BR]] So by my testing - the fix for them is to just re-save all their
 custom structures on the permalink screen.

 Testing that theory didn't seem work for me in production. But locally I
 did it 3 times and it did exactly what I expected.

 If I did: ?staff=test-member it works as expected.

 After changing the permalinks to '/%category%/%postname%/' it still
 presents the same problem.
 [[BR]]URL would be: /staff/test-member/

 But this works of course: /staff/test-member/?staff=test-member

 Could someone else do some testing on their end and see what they come up
 with?

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/15943#comment:10>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list