| | 15 | * Creates the initial post types when 'init' action is fired. |
| | 16 | */ |
| | 17 | function create_initial_post_types() { |
| | 18 | register_post_type( 'post', array('exclude_from_search' => false) ); |
| | 19 | register_post_type( 'page', array('exclude_from_search' => false) ); |
| | 20 | register_post_type( 'attachment', array('exclude_from_search' => false) ); |
| | 21 | register_post_type( 'revision', array('exclude_from_search' => true) ); |
| | 22 | } |
| | 23 | add_action( 'init', 'create_initial_post_types', 0 ); // highest priority |
| | 24 | |
| | 25 | /** |
| | 426 | * Get a list of all registered post types. |
| | 427 | * |
| | 428 | * @package WordPress |
| | 429 | * @subpackage Post |
| | 430 | * @since 2.9.0 |
| | 431 | * @uses $wp_post_types |
| | 432 | * @see register_post_type |
| | 433 | * |
| | 434 | * @param array|string $args An array of key => value arguments to match against the post types. |
| | 435 | * Only post types having attributes that match all arguments are returned. |
| | 436 | * @return array A list of post type objects |
| | 437 | */ |
| | 438 | function get_post_types( $args = array() ) { |
| | 439 | global $wp_post_types; |
| | 440 | |
| | 441 | $post_types = array(); |
| | 442 | foreach ( (array) $wp_post_types as $post_type ) { |
| | 443 | if ( empty($args) ) |
| | 444 | $post_types[] = $post_type->name; |
| | 445 | elseif ( array_intersect((array) $post_type, $args) ) |
| | 446 | $post_types[] = $post_type->name; |
| | 447 | } |
| | 448 | |
| | 449 | return $post_types; |
| | 450 | } |
| | 451 | |
| | 452 | /** |
| | 453 | * Register a post type. Do not use before init. |
| | 454 | * |
| | 455 | * A simple function for creating or modifying a post type based on the |
| | 456 | * parameters given. The function will accept an array (second optional |
| | 457 | * parameter), along with a string for the post type name. |
| | 458 | * |
| | 459 | * |
| | 460 | * Optional $args contents: |
| | 461 | * |
| | 462 | * exclude_from_search - Whether to exclude posts with this post type from search results. Defaults to true. |
| | 463 | * |
| | 464 | * @package WordPress |
| | 465 | * @subpackage Post |
| | 466 | * @since 2.9.0 |
| | 467 | * @uses $wp_post_types Inserts new post type object into the list |
| | 468 | * |
| | 469 | * @param string $post_type Name of the post type. |
| | 470 | * @param array|string $args See above description. |
| | 471 | */ |
| | 472 | function register_post_type($post_type, $args = array()) { |
| | 473 | global $wp_post_types; |
| | 474 | |
| | 475 | if (!is_array($wp_post_types)) |
| | 476 | $wp_post_types = array(); |
| | 477 | |
| | 478 | $defaults = array('exclude_from_search' => true); |
| | 479 | $args = wp_parse_args($args, $defaults); |
| | 480 | |
| | 481 | $post_type = sanitize_user($post_type, true); |
| | 482 | $args['name'] = $post_type; |
| | 483 | $wp_post_types[$post_type] = (object) $args; |
| | 484 | } |
| | 485 | |
| | 486 | /** |