Make WordPress Core

Opened 2 years ago

Last modified 2 years ago

#55638 new defect (bug)

Undefined property: WP_Post_Type::$post_type

Reported by: pienoz's profile pienoz Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 5.9.3
Component: Posts, Post Types Keywords:
Focuses: Cc:

Description

PHP 8.1.5

PHP Warning: Undefined property: WP_Post_Type::$post_type in wp-includes/post-template.php on line 649

Attachments (2)

single-programme.php (8.7 KB) - added by pienoz 2 years ago.
header.php (2.3 KB) - added by pienoz 2 years ago.

Download all attachments as: .zip

Change History (10)

#1 @jrf
2 years ago

@pienoz Please provide a backtrace of the error you are seeing.

#2 @costdev
2 years ago

  • Keywords reporter-feedback added

The line referenced (649) points to:

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

So:

As Juliette said, we need more information including the backtrace and reproduction steps.

@pienoz please provide this so that we can investigate this issue further, or let us know if you have determined that the issue is not caused by WordPress Core.

#3 @SergeyBiryukov
2 years ago

  • Component changed from General to Posts, Post Types

#4 @pienoz
2 years ago

  • Keywords reporter-feedback removed

backtrace with query monitor :

wp-includes/post-template.php:649
get_body_class()
wp-includes/post-template.php:595
body_class()
wp-content/themes/sud-radio/header.php:57
load_template('wp-content/themes/sud-radio/header.php')
wp-includes/template.php:716
locate_template()
wp-includes/general-template.php:48
get_header()
wp-content/themes/sud-radio/single-programme.php:33

@pienoz
2 years ago

#5 @jrf
2 years ago

@pienoz While Query monitor gives some form of backtrace, this is not a proper backtrace containing all information needed.

Having said that, it points to line 33 of the wp-content/themes/sud-radio/single-programme.php file in your theme, which reads get_template_part('phpincludes/menu'); (based on the file you uploaded). As the phpincludes/menu file has not been uploaded, I can't look at it, but it strongly suggests that there error is in that file.

In other words: please contact the author of your theme to fix the theme.

#6 @pienoz
2 years ago

1°) I have delete all code after get_header(); (i have a blank page) and the message is still there.

2°) I have add

error_log(print_r($post,true)); in post-template.php line 649 

the error_log content :

[02-May-2022 08:42:41 UTC] WP_Post_Type Object
(
    [name] => emission
    [label] => Épisodes
    [labels] => stdClass Object
        (
            [name] => Épisodes
            [singular_name] => épisode
            [add_new] => Ajouter un épisode
            [add_new_item] => Ajouter
            [edit_item] => Editer
            [new_item] => Ajouter
            [view_item] => Voir un épisode
            [view_items] => Voir les articles
            [search_items] => Rechercher un épisode
            [not_found] => Aucune épisode trouvé
            [not_found_in_trash] => Aucun épisode trouvé
            [parent_item_colon] =>
            [all_items] => Tous les épisodes
            [archives] => Tous les épisodes
            [attributes] => Attributs d’articles
            [insert_into_item] => Insérer dans la publication
            [uploaded_to_this_item] => Téléversés sur cette publication
            [featured_image] => Image mise en avant
            [set_featured_image] => Définir l’image mise en avant
            [remove_featured_image] => Supprimer l’image mise en avant
            [use_featured_image] => Utiliser comme image mise en avant
            [filter_items_list] => Filtrer la liste des articles
            [filter_by_date] => Filtrer par date
            [items_list_navigation] => Navigation de la liste des articles
            [items_list] => Liste des articles
            [item_published] => Publication mise en ligne.
            [item_published_privately] => Publication mise en ligne en privé.
            [item_reverted_to_draft] => Publication reconvertie en brouillon.
            [item_scheduled] => Publication planifiée.
            [item_updated] => Publication mise à jour.
            [item_link] => Lien d’article
            [item_link_description] => Un lien vers une publication.
            [menu_name] => Épisodes
            [name_admin_bar] => épisode
        )

    [description] =>
    [public] => 1
    [hierarchical] =>
    [exclude_from_search] =>
    [publicly_queryable] => 1
    [show_ui] => 1
    [show_in_menu] => 1
    [show_in_nav_menus] => 1
    [show_in_admin_bar] => 1
    [menu_position] => 20
    [menu_icon] => dashicons-megaphone
    [capability_type] => page
    [map_meta_cap] => 1
    [register_meta_box_cb] =>
    [taxonomies] => Array
        (
        )

    [has_archive] => 1
    [query_var] => emission
    [can_export] => 1
    [delete_with_user] =>
    [template] => Array
        (
        )

    [template_lock] =>
    [_builtin] =>
    [_edit_link] => post.php?post=%d
    [cap] => stdClass Object
        (
            [edit_post] => edit_page
            [read_post] => read_page
            [delete_post] => delete_page
            [edit_posts] => edit_pages
            [edit_others_posts] => edit_others_pages
            [delete_posts] => delete_pages
            [publish_posts] => publish_pages
            [read_private_posts] => read_private_pages
            [read] => read
            [delete_private_posts] => delete_private_pages
            [delete_published_posts] => delete_published_pages
            [delete_others_posts] => delete_others_pages
            [edit_private_posts] => edit_private_pages
            [edit_published_posts] => edit_published_pages
            [create_posts] => edit_pages
        )

    [rewrite] => Array
        (
            [slug] => emission
            [with_front] => 1
            [pages] => 1
            [feeds] => 1
            [ep_mask] => 1
        )

    [show_in_rest] => 1
    [rest_base] =>
    [rest_namespace] => wp/v2
    [rest_controller_class] =>
    [rest_controller] =>
    [ID] => 0
    [filter] => raw
)

[02-May-2022 08:42:41 UTC] PHP Warning:  Undefined property: WP_Post_Type::$post_type in /mnt/data/web-test/fr.sudradio.www/wp-includes/post-template.php on line 651
Last edited 2 years ago by SergeyBiryukov (previous) (diff)

#7 @jrf
2 years ago

@pienoz Var dumping the query does not replace a backtrace and is not actually that helpful.

The theme is overwriting the main WP query for the loop. Whatever breakage that causes is something for the theme to fix.

Also see: https://developer.wordpress.org/reference/functions/query_posts/

#8 @pienoz
2 years ago

I have resolved my problem :

In single-programm.php I have change the order line code :

Before :

...
global $wp_query;
query_posts($args);
...
get_header();

After :

get_header();
...
global $wp_query;
query_posts($args);

Note: See TracTickets for help on using tickets.