[wp-trac] [WordPress Trac] #19958: Allow custom post types as "home"

WordPress Trac noreply at wordpress.org
Sun Nov 25 20:49:01 UTC 2012


#19958: Allow custom post types as "home"
----------------------------+------------------------------
 Reporter:  sooskriszta     |       Owner:
     Type:  enhancement     |      Status:  new
 Priority:  normal          |   Milestone:  Awaiting Review
Component:  Administration  |     Version:  3.3.1
 Severity:  major           |  Resolution:
 Keywords:                  |
----------------------------+------------------------------

Comment (by pbearne):

 Hi


 I have done some work on this but have not sorted the URL code

 So I am just pasting the patch for now


 {{{
 Index: wp-admin/options-reading.php
 ===================================================================
 --- wp-admin/options-reading.php        (revision 22831)
 +++ wp-admin/options-reading.php        (working copy)
 @@ -114,7 +114,7 @@
         </label>
         </p>
  <ul>
 -       <li><label for="page_on_front"><?php printf( __( 'Front page: %s'
 ), wp_dropdown_pages( array( 'name' => 'page_on_front', 'echo' => 0,
 'show_option_none' => __( '&mdash; Select &mdash;' ), 'option_none_value'
 => '0', 'selected' => get_option( 'page_on_front' ) ) ) ); ?></label></li>
 +       <li><label for="page_on_front"><?php printf( __( 'Front page: %s'
 ), wp_dropdown_pages( apply_filters('options-front-page',array( 'name' =>
 'page_on_front', 'echo' => 0, 'show_option_none' => __( '&mdash; Select
 &mdash;' ), 'option_none_value' => '0', 'selected' => get_option(
 'page_on_front' ) ) ) ) ); ?></label></li>
         <li><label for="page_for_posts"><?php printf( __( 'Posts page: %s'
 ), wp_dropdown_pages( array( 'name' => 'page_for_posts', 'echo' => 0,
 'show_option_none' => __( '&mdash; Select &mdash;' ), 'option_none_value'
 => '0', 'selected' => get_option( 'page_for_posts' ) ) ) );
 ?></label></li>
  </ul>
  <?php if ( 'page' == get_option( 'show_on_front' ) && get_option(
 'page_for_posts' ) == get_option( 'page_on_front' ) ) : ?>
 Index: wp-includes/post.php
 ===================================================================
 --- wp-includes/post.php        (revision 22831)
 +++ wp-includes/post.php        (working copy)
 @@ -3628,9 +3628,14 @@
         $number = (int) $number;
         $offset = (int) $offset;

 -       // Make sure the post type is hierarchical
 +       // Make sure we have a valid post type
 +       if ( !is_array( $post_type ) )
 +               $post_type = explode( ',', $post_type );
 +       if ( array_diff( $post_type, get_post_types() ) )
 +               return $pages;
 +       // Make sure the all post types are hierarchical
         $hierarchical_post_types = get_post_types( array( 'hierarchical'
 => true ) );
 -       if ( !in_array( $post_type, $hierarchical_post_types ) )
 +       if ( array_intersect( $post_type, $hierarchical_post_types ) ==
 count($post_type) )
                 return $pages;

         // Make sure we have a valid post status
 @@ -3733,11 +3738,19 @@
         if ( $parent >= 0 )
                 $where .= $wpdb->prepare(' AND post_parent = %d ',
 $parent);

 +       // Check if post_type is an array so that Custom Page types can be
 added to dropdowns and lists
 +       if ( 1 == count( $post_type ) ) {
 +               $where_post_type = $wpdb->prepare("post_type = %s"  ,
 array_shift( $post_type ) );
 +       } else{
 +               $post_type = implode( "', '", $post_type );
 +               $where_post_type = "post_type IN ('$post_type')";
 +       }
 +
         if ( 1 == count( $post_status ) ) {
 -               $where_post_type = $wpdb->prepare( "post_type = %s AND
 post_status = %s", $post_type, array_shift( $post_status ) );
 +               $where_post_type .= $wpdb->prepare( " AND post_status =
 %s",  array_shift( $post_status ) );
         } else {
                 $post_status = implode( "', '", $post_status );
 -               $where_post_type = $wpdb->prepare( "post_type = %s AND
 post_status IN ('$post_status')", $post_type );
 +               $where_post_type .= "AND post_status IN ('$post_status')"
 ;
         }

         $orderby_array = array();

 }}}

 the test functions I used where


 {{{
 add_action( 'init', 'create_post_type' );
 function create_post_type() {
         register_post_type( 'acme_product',
                 array(
                         'labels' => array(
                                 'name' => __( 'tests' ),
                                 'singular_name' => __( 'test' )
                         ),
                         'public' => true,
                         'has_archive' => true,
                         'rewrite' => array('slug' => 'tests'),
                 )
         );
 }


 function filter_my_cpt($args) {
         $args['post_type'] = array('page', 'acme_product');
         return $args;
 }

 add_filter('options-front-page' , 'filter_my_cpt');
 }}}

 I will look at the URl code later

 And I want to look getting this into the register_post_type() call

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


More information about the wp-trac mailing list