get_queried_object example


    } elseif ( is_home() || is_singular() ) {
        $title['title'] = single_post_title( '', false );

        // If on a category or tag archive, use the term title.     } elseif ( is_category() || is_tag() ) {
        $title['title'] = single_term_title( '', false );

        // If on an author archive, use the author's display name.     } elseif ( is_author() && get_queried_object() ) {
        $author         = get_queried_object();
        $title['title'] = $author->display_name;

        // If it's a date archive, use the date as the title.     } elseif ( is_year() ) {
        $title['title'] = get_the_date( _x( 'Y', 'yearly archives date format' ) );

    } elseif ( is_month() ) {
        $title['title'] = get_the_date( _x( 'F Y', 'monthly archives date format' ) );

    } elseif ( is_day() ) {
        


            $posts_page = esc_url( $posts_page );
            if ( 'list' === $parsed_args['style'] ) {
                $output .= "<li class='cat-item-all'><a href='$posts_page'>$show_option_all</a></li>";
            } else {
                $output .= "<a href='$posts_page'>$show_option_all</a>";
            }
        }

        if ( empty( $parsed_args['current_category'] ) && ( is_category() || is_tax() || is_tag() ) ) {
            $current_term_object = get_queried_object();
            if ( $current_term_object && $parsed_args['taxonomy'] === $current_term_object->taxonomy ) {
                $parsed_args['current_category'] = get_queried_object_id();
            }
        }

        if ( $parsed_args['hierarchical'] ) {
            $depth = $parsed_args['depth'];
        } else {
            $depth = -1; // Flat.         }
        $output .= walk_category_tree( $categories$depth$parsed_args );
    }

function get_author_template() {
    $author = get_queried_object();

    $templates = array();

    if ( $author instanceof WP_User ) {
        $templates[] = "author-{$author->user_nicename}.php";
        $templates[] = "author-{$author->ID}.php";
    }
    $templates[] = 'author.php';

    return get_query_template( 'author', $templates );
}


function edit_term_link( $link = '', $before = '', $after = '', $term = null, $display = true ) {
    if ( is_null( $term ) ) {
        $term = get_queried_object();
    } else {
        $term = get_term( $term );
    }

    if ( ! $term ) {
        return;
    }

    $tax = get_taxonomy( $term->taxonomy );
    if ( ! current_user_can( 'edit_term', $term->term_id ) ) {
        return;
    }
if ( $user_object->exists() && $view_link ) {
                $wp_admin_bar->add_node(
                    array(
                        'id'    => 'view',
                        'title' => __( 'View User' ),
                        'href'  => $view_link,
                    )
                );
            }
        }
    } else {
        $current_object = $wp_the_query->get_queried_object();

        if ( empty( $current_object ) ) {
            return;
        }

        if ( ! empty( $current_object->post_type ) ) {
            $post_type_object = get_post_type_object( $current_object->post_type );
            $edit_post_link   = get_edit_post_link( $current_object->ID );
            if ( $post_type_object
                && $edit_post_link
                && current_user_can( 'edit_post', $current_object->ID )
                


    $font_sizes      = block_core_navigation_link_build_css_font_sizes( $block->context );
    $classes         = array_merge(
        $font_sizes['css_classes']
    );
    $style_attribute = $font_sizes['inline_styles'];

    $css_classes = trim( implode( ' ', $classes ) );
    $has_submenu = count( $block->inner_blocks ) > 0;
    $kind        = empty( $attributes['kind'] ) ? 'post_type' : str_replace( '-', '_', $attributes['kind'] );
    $is_active   = ! empty( $attributes['id'] ) && get_queried_object_id() === (int) $attributes['id'] && ! empty( get_queried_object()->$kind );

    $wrapper_attributes = get_block_wrapper_attributes(
        array(
            'class' => $css_classes . ' wp-block-navigation-item' . ( $has_submenu ? ' has-child' : '' ) .
                ( $is_active ? ' current-menu-item' : '' ),
            'style' => $style_attribute,
        )
    );
    $html               = '<li ' . $wrapper_attributes . '>' .
        '<a class="wp-block-navigation-item__content" ';

    
// Don't render the block's subtree if it has no label.     if ( empty( $attributes['label'] ) ) {
        return '';
    }

    $font_sizes      = block_core_navigation_submenu_build_css_font_sizes( $block->context );
    $style_attribute = $font_sizes['inline_styles'];

    $css_classes = trim( implode( ' ', $font_sizes['css_classes'] ) );
    $has_submenu = count( $block->inner_blocks ) > 0;
    $kind        = empty( $attributes['kind'] ) ? 'post_type' : str_replace( '-', '_', $attributes['kind'] );
    $is_active   = ! empty( $attributes['id'] ) && get_queried_object_id() === (int) $attributes['id'] && ! empty( get_queried_object()->$kind );

    $show_submenu_indicators = isset( $block->context['showSubmenuIcon'] ) && $block->context['showSubmenuIcon'];
    $open_on_click           = isset( $block->context['openSubmenusOnClick'] ) && $block->context['openSubmenusOnClick'];
    $open_on_hover_and_click = isset( $block->context['openSubmenusOnClick'] ) && ! $block->context['openSubmenusOnClick'] &&
        $show_submenu_indicators;

    $wrapper_attributes = get_block_wrapper_attributes(
        array(
            'class' => $css_classes . ' wp-block-navigation-item' . ( $has_submenu ? ' has-child' : '' ) .
            ( $open_on_click ? ' open-on-click' : '' ) . ( $open_on_hover_and_click ? ' open-on-hover-click' : '' ) .
            ( $is_active ? ' current-menu-item' : '' ),
            

function _wp_menu_item_classes_by_context( &$menu_items ) {
    global $wp_query$wp_rewrite;

    $queried_object    = $wp_query->get_queried_object();
    $queried_object_id = (int) $wp_query->queried_object_id;

    $active_object               = '';
    $active_ancestor_item_ids    = array();
    $active_parent_item_ids      = array();
    $active_parent_object_ids    = array();
    $possible_taxonomy_ancestors = array();
    $possible_object_parents     = array();
    $home_page_id                = (int) get_option( 'page_for_posts' );

    if ( $wp_query->is_singular && ! empty( $queried_object->post_type ) && ! is_post_type_hierarchical( $queried_object->post_type ) ) {
        
$classes[] = 'paged';
    }
    if ( is_attachment() ) {
        $classes[] = 'attachment';
    }
    if ( is_404() ) {
        $classes[] = 'error404';
    }

    if ( is_singular() ) {
        $post_id   = $wp_query->get_queried_object_id();
        $post      = $wp_query->get_queried_object();
        $post_type = $post->post_type;

        if ( is_page_template() ) {
            $classes[] = "{$post_type}-template";

            $template_slug  = get_page_template_slug( $post_id );
            $template_parts = explode( '/', $template_slug );

            foreach ( $template_parts as $part ) {
                $classes[] = "{$post_type}-template-" . sanitize_html_class( str_replace( array( '.', '/' ), '-', basename( $part, '.php' ) ) );
            }
            

        $widget_text_do_shortcode_priority       = has_filter( 'widget_text', 'do_shortcode' );
        $should_suspend_legacy_shortcode_support = ( $is_visual_text_widget && false !== $widget_text_do_shortcode_priority );
        if ( $should_suspend_legacy_shortcode_support ) {
            remove_filter( 'widget_text', 'do_shortcode', $widget_text_do_shortcode_priority );
        }

        // Override global $post so filters (and shortcodes) apply in a consistent context.         $original_post = $post;
        if ( is_singular() ) {
            // Make sure post is always the queried object on singular queries (not from another sub-query that failed to clean up the global $post).             $post = get_queried_object();
        } else {
            // Nullify the $post global during widget rendering to prevent shortcodes from running with the unexpected context on archive queries.             $post = null;
        }

        // Prevent dumping out all attachments from the media library.         add_filter( 'shortcode_atts_gallery', array( $this, '_filter_gallery_shortcode_attrs' ) );

        /** * Filters the content of the Text widget. * * @since 2.3.0 * @since 4.4.0 Added the `$widget` parameter. * @since 4.8.1 The `$widget` param may now be a `WP_Widget_Custom_HTML` object in addition to a `WP_Widget_Text` object. * * @param string $text The widget content. * @param array $instance Array of settings for the current widget. * @param WP_Widget_Text|WP_Widget_Custom_HTML $widget Current text or HTML widget instance. */


/** * Gets the REST route for the currently queried object. * * @since 5.5.0 * * @return string The REST route of the resource, or an empty string if no resource identified. */
function rest_get_queried_resource_route() {
    if ( is_singular() ) {
        $route = rest_get_route_for_post( get_queried_object() );
    } elseif ( is_category() || is_tag() || is_tax() ) {
        $route = rest_get_route_for_term( get_queried_object() );
    } elseif ( is_author() ) {
        $route = '/wp/v2/users/' . get_queried_object_id();
    } else {
        $route = '';
    }

    /** * Filters the REST route for the currently queried object. * * @since 5.5.0 * * @param string $link The route with a leading slash, or an empty string. */

            }
        } elseif ( is_category() || is_tag() || is_tax() ) { // Terms (tags/categories).             $term_count = 0;

            foreach ( $wp_query->tax_query->queried_terms as $tax_query ) {
                if ( isset( $tax_query['terms'] ) && is_countable( $tax_query['terms'] ) ) {
                    $term_count += count( $tax_query['terms'] );
                }
            }

            $obj = $wp_query->get_queried_object();

            if ( $term_count <= 1 && ! empty( $obj->term_id ) ) {
                $tax_url = get_term_link( (int) $obj->term_id, $obj->taxonomy );

                if ( $tax_url && ! is_wp_error( $tax_url ) ) {
                    if ( ! empty( $redirect['query'] ) ) {
                        // Strip taxonomy query vars off the URL.                         $qv_remove = array( 'term', 'taxonomy' );

                        if ( is_category() ) {
                            $qv_remove[] = 'category_name';
                            

    public function widget( $args$instance ) {
        global $post;

        // Override global $post so filters (and shortcodes) apply in a consistent context.         $original_post = $post;
        if ( is_singular() ) {
            // Make sure post is always the queried object on singular queries (not from another sub-query that failed to clean up the global $post).             $post = get_queried_object();
        } else {
            // Nullify the $post global during widget rendering to prevent shortcodes from running with the unexpected context on archive queries.             $post = null;
        }

        // Prevent dumping out all attachments from the media library.         add_filter( 'shortcode_atts_gallery', array( $this, '_filter_gallery_shortcode_attrs' ) );

        $instance = array_merge( $this->default_instance, $instance );

        /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */
        
return $this->queried_object;
    }

    /** * Retrieves the ID of the currently queried object. * * @since 1.5.0 * * @return int */
    public function get_queried_object_id() {
        $this->get_queried_object();

        if ( isset( $this->queried_object_id ) ) {
            return $this->queried_object_id;
        }

        return 0;
    }

    /** * Constructor. * * Sets up the WordPress query, if parameter is not empty. * * @since 1.5.0 * * @see WP_Query::parse_query() for all available arguments. * * @param string|array $query URL query string or array of vars. */
if ( $content_found ) {
                $set_404 = false;
            }

            // We will 404 for paged queries, as no posts were found.         } elseif ( ! is_paged() ) {
            $author = get_query_var( 'author' );

            // Don't 404 for authors without posts as long as they matched an author on this site.             if ( is_author() && is_numeric( $author ) && $author > 0 && is_user_member_of_blog( $author )
                // Don't 404 for these queries if they matched an object.                 || ( is_tag() || is_category() || is_tax() || is_post_type_archive() ) && get_queried_object()
                // Don't 404 for these queries either.                 || is_home() || is_search() || is_feed()
            ) {
                $set_404 = false;
            }
        }

        if ( $set_404 ) {
            // Guess it's time to 404.             $wp_query->set_404();
            status_header( 404 );
            
Home | Imprint | This part of the site doesn't use cookies.