onth() { return (bool) $this->is_month; } /** * Is the query for an existing single page? * * If the $page parameter is specified, this function will additionally * check if the query is for one of the pages specified. * * @see WP_Query::is_single() * @see WP_Query::is_singular() * * @since 3.1.0 * * @param mixed $page Page ID, title, slug, or array of such. * @return bool */ function is_page( $page = '' ) { if ( !$this->is_page ) return false; if ( empty( $page ) ) return true; $page_obj = $this->get_queried_object(); $page = (array) $page; if ( in_array( $page_obj->ID, $page ) ) return true; elseif ( in_array( $page_obj->post_title, $page ) ) return true; else if ( in_array( $page_obj->post_name, $page ) ) return true; return false; } /** * Is the query for paged result and not for the first page? * * @since 3.1.0 * * @return bool */ function is_paged() { return (bool) $this->is_paged; } /** * Is the query for a post or page preview? * * @since 3.1.0 * * @return bool */ function is_preview() { return (bool) $this->is_preview; } /** * Is the query for the robots file? * * @since 3.1.0 * * @return bool */ function is_robots() { return (bool) $this->is_robots; } /** * Is the query for a search? * * @since 3.1.0 * * @return bool */ function is_search() { return (bool) $this->is_search; } /** * Is the query for an existing single post? * * Works for any post type, except attachments and pages * * If the $post parameter is specified, this function will additionally * check if the query is for one of the Posts specified. * * @see WP_Query::is_page() * @see WP_Query::is_singular() * * @since 3.1.0 * * @param mixed $post Post ID, title, slug, or array of such. * @return bool */ function is_single( $post = '' ) { if ( !$this->is_single ) return false; if ( empty($post) ) return true; $post_obj = $this->get_queried_object(); $post = (array) $post; if ( in_array( $post_obj->ID, $post ) ) return true; elseif ( in_array( $post_obj->post_title, $post ) ) return true; elseif ( in_array( $post_obj->post_name, $post ) ) return true; return false; } /** * Is the query for an existing single post of any post type (post, attachment, page, ... )? * * If the $post_types parameter is specified, this function will additionally * check if the query is for one of the Posts Types specified. * * @see WP_Query::is_page() * @see WP_Query::is_single() * * @since 3.1.0 * * @param mixed $post_types Optional. Post Type or array of Post Types * @return bool */ function is_singular( $post_types = '' ) { if ( empty( $post_types ) || !$this->is_singular ) return (bool) $this->is_singular; $post_obj = $this->get_queried_object(); return in_array( $post_obj->post_type, (array) $post_types ); } /** * Is the query for a specific time? * * @since 3.1.0 * * @return bool */ function is_time() { return (bool) $this->is_time; } /** * Is the query for a trackback endpoint call? * * @since 3.1.0 * * @return bool */ function is_trackback() { return (bool) $this->is_trackback; } /** * Is the query for an existing year archive? * * @since 3.1.0 * * @return bool */ function is_year() { return (bool) $this->is_year; } /** * Is the query a 404 (returns no results)? * * @since 3.1.0 * * @return bool */ function is_404() { return (bool) $this->is_404; } /** * Is the query the main query? * * @since 3.3.0 * * @return bool */ function is_main_query() { global $wp_the_query; return $wp_the_query === $this; } /** * After looping through a nested query, this function * restores the $post global to the current post in this query. * * @since 3.7.0 * * @return bool */ function reset_postdata() { if ( ! empty( $this->post ) ) { $GLOBALS['post'] = $this->post; setup_postdata( $this->post ); } } } /** * Redirect old slugs to the correct permalink. * * Attempts to find the current slug from the past slugs. * * @since 2.1.0 * @uses $wp_query * @uses $wpdb * * @return null If no link is found, null is returned. */ function wp_old_slug_redirect() { global $wp_query; if ( is_404() && '' != $wp_query->query_vars['name'] ) : global $wpdb; // Guess the current post_type based on the query vars. if ( get_query_var('post_type') ) $post_type = get_query_var('post_type'); elseif ( !empty($wp_query->query_vars['pagename']) ) $post_type = 'page'; else $post_type = 'post'; if ( is_array( $post_type ) ) { if ( count( $post_type ) > 1 ) return; $post_type = array_shift( $post_type ); } // Do not attempt redirect for hierarchical post types if ( is_post_type_hierarchical( $post_type ) ) return; $query = $wpdb->prepare("SELECT post_id FROM $wpdb->postmeta, $wpdb->posts WHERE ID = post_id AND post_type = %s AND meta_key = '_wp_old_slug' AND meta_value = %s", $post_type, $wp_query->query_vars['name']); // if year, monthnum, or day have been specified, make our query more precise // just in case there are multiple identical _wp_old_slug values if ( '' != $wp_query->query_vars['year'] ) $query .= $wpdb->prepare(" AND YEAR(post_date) = %d", $wp_query->query_vars['year']); if ( '' != $wp_query->query_vars['monthnum'] ) $query .= $wpdb->prepare(" AND MONTH(post_date) = %d", $wp_query->query_vars['monthnum']); if ( '' != $wp_query->query_vars['day'] ) $query .= $wpdb->prepare(" AND DAYOFMONTH(post_date) = %d", $wp_query->query_vars['day']); $id = (int) $wpdb->get_var($query); if ( ! $id ) return; $link = get_permalink($id); if ( !$link ) return; wp_redirect( $link, 301 ); // Permanent redirect exit; endif; } /** * Set up global post data. * * @since 1.5.0 * * @param object $post Post data. * @uses do_action_ref_array() Calls 'the_post' * @return bool True when finished. */ function setup_postdata( $post ) { global $id, $authordata, $currentday, $currentmonth, $page, $pages, $multipage, $more, $numpages; $id = (int) $post->ID; $authordata = get_userdata($post->post_author); $currentday = mysql2date('d.m.y', $post->post_date, false); $currentmonth = mysql2date('m', $post->post_date, false); $numpages = 1; $multipage = 0; $page = get_query_var('page'); if ( ! $page ) $page = 1; if ( is_single() || is_page() || is_feed() ) $more = 1; $content = $post->post_content; if ( false !== strpos( $content, '' ) ) { if ( $page > 1 ) $more = 1; $content = str_replace( "\n\n", '', $content ); $content = str_replace( "\n", '', $content ); $content = str_replace( "\n", '', $content ); // Ignore nextpage at the beginning of the content. if ( 0 === strpos( $content, '' ) ) $content = substr( $content, 15 ); $pages = explode('', $content); $numpages = count($pages); if ( $numpages > 1 ) $multipage = 1; } else { $pages = array( $post->post_content ); } do_action_ref_array('the_post', array(&$post)); return true; }