Make WordPress Core

Ticket #9674: 9674.17.diff

File 9674.17.diff, 3.9 KB (added by prettyboymp, 15 years ago)

allows post_type to be set as public query var by limiting it to post_types with 'publicly_queryable' value set to true

  • wp-includes/post.php

     
    1616 */
    1717function create_initial_post_types() {
    1818        register_post_type( 'post', array(      'label' => __('Posts'),
     19                                                                                'publicly_queryable' => true,
    1920                                                                                'exclude_from_search' => false,
    2021                                                                                '_builtin' => true,
    2122                                                                                '_edit_link' => 'post.php?post=%d',
     
    2526                                                                        ) );
    2627
    2728        register_post_type( 'page', array(      'label' => __('Pages'),
     29                                                                                'publicly_queryable' => true,
    2830                                                                                'exclude_from_search' => false,
    2931                                                                                '_builtin' => true,
    3032                                                                                '_edit_link' => 'post.php?post=%d',
     
    707709                $wp_post_types = array();
    708710
    709711        // Args prefixed with an underscore are reserved for internal use.
    710         $defaults = array('label' => false, 'exclude_from_search' => true, '_builtin' => false, '_edit_link' => 'post.php?post=%d', 'capability_type' => 'post', 'hierarchical' => false, 'public' => false, '_show' => false, 'supports' => array());
     712        $defaults = array('label' => false, 'publicly_queryable' => false, 'exclude_from_search' => true, '_builtin' => false, '_edit_link' => 'post.php?post=%d', 'capability_type' => 'post', 'hierarchical' => false, 'public' => false, '_show' => false, 'supports' => array());
    711713        $args = wp_parse_args($args, $defaults);
    712714        $args = (object) $args;
    713715
  • wp-includes/classes.php

     
    2626         * @access public
    2727         * @var array
    2828         */
    29         var $public_query_vars = array('m', 'p', 'posts', 'w', 'cat', 'withcomments', 'withoutcomments', 's', 'search', 'exact', 'sentence', 'debug', 'calendar', 'page', 'paged', 'more', 'tb', 'pb', 'author', 'order', 'orderby', 'year', 'monthnum', 'day', 'hour', 'minute', 'second', 'name', 'category_name', 'tag', 'feed', 'author_name', 'static', 'pagename', 'page_id', 'error', 'comments_popup', 'attachment', 'attachment_id', 'subpost', 'subpost_id', 'preview', 'robots', 'taxonomy', 'term', 'cpage');
     29        var $public_query_vars = array('m', 'p', 'posts', 'w', 'cat', 'withcomments', 'withoutcomments', 's', 'search', 'exact', 'sentence', 'debug', 'calendar', 'page', 'paged', 'more', 'tb', 'pb', 'author', 'order', 'orderby', 'year', 'monthnum', 'day', 'hour', 'minute', 'second', 'name', 'category_name', 'tag', 'feed', 'author_name', 'static', 'pagename', 'page_id', 'error', 'comments_popup', 'attachment', 'attachment_id', 'subpost', 'subpost_id', 'preview', 'robots', 'taxonomy', 'term', 'cpage', 'post_type');
    3030
    3131        /**
    3232         * Private query variables.
     
    3636         * @since 2.0.0
    3737         * @var array
    3838         */
    39         var $private_query_vars = array('offset', 'posts_per_page', 'posts_per_archive_page', 'showposts', 'nopaging', 'post_type', 'post_status', 'category__in', 'category__not_in', 'category__and', 'tag__in', 'tag__not_in', 'tag__and', 'tag_slug__in', 'tag_slug__and', 'tag_id', 'post_mime_type', 'perm', 'comments_per_page');
     39        var $private_query_vars = array('offset', 'posts_per_page', 'posts_per_archive_page', 'showposts', 'nopaging', 'post_status', 'category__in', 'category__not_in', 'category__and', 'tag__in', 'tag__not_in', 'tag__and', 'tag_slug__in', 'tag_slug__and', 'tag_id', 'post_mime_type', 'perm', 'comments_per_page');
    4040
    4141        /**
    4242         * Extra query variables set by the user.
     
    277277                                }
    278278                        }
    279279                }
     280               
     281                //limit publicly queried post_types to those that are publicly_queryable
     282                if( isset( $this->query_vars['post_type'])) {
     283                        $queryable_post_types =  get_post_types( array('publicly_queryable' => true) );
     284                        if( ! in_array( $this->query_vars['post_type'], $queryable_post_types ) )
     285                                unset( $this->query_vars['post_type'] );
     286                }
    280287
    281288                foreach ( (array) $this->private_query_vars as $var) {
    282289                        if (isset($this->extra_query_vars[$var]))