I am trying to code a simple theme, everything works well except one thing and I can’t understand the issue, I’ve tried everything I just can’t get rid of this notice:
Notice : Undefined property: WP_Post_Type::$term_id in /home/tibi/public_html/wp/wp-includes/nav-menu-template.php on line 32
I have a custom post type with a taxonomy, if I set hierarchical to true I get this notice, I just don’t get it why is this happening?
It seams that if I add the below code it fixes the issue, I have no idea why or how it works, maybe someone with experience can explain this to me.
add_action(‘parse_query’, ‘wpse_71157_parse_query’);
function wpse_71157_parse_query($wp_query){
if ($wp_query->is_post_type_archive) $wp_query->is_post_type_archive = false;
if ($wp_query->is_post_type_archive) $wp_query->is_post_type_archive = false;
}
I don’t want to pay anybody is a simple question for other developers out here makes no sense to pay for something like this, I am sure other had this error / bug. Anyway I solved it.
@unlockdesign hey we all know you get badges for posting these, but please be on topic as this way you’re just spamming this forum. thanks.
@FWDesign the code that you’ve added isn’t advised to be used at anytime. so, remove the code, then you’ll need to investigate what went wrong. error says – “Notice : Undefined property: WP_Post_Type::$term_id in /home/tibi/public_html/wp/wp-includes/nav-menu-template.php on line 32” – which means that when your nav menu is generated (i’d assume on the front end) some terms that are in the menu aren’t properly set. this can also mean that if you’ve edited nav menu code with filters and functions there might be your issue, but if you didn’t, what i suggest is investigating your nav menu that’s making all fuzz. for start, remove all the custom taxonomy links you’ve added to your menu, then just add those again, it might fix it, if not you’ll see which ones are causing issues and then check them under your taxonomy page. also, a clue is the hierarchy switching on and off, so you might have just played with those terms and got them to be faulty, so remove those add again, or similar…
this is all that can be assumed on the error you’ve posted and not looking at anything you wrote there. thanks!
Thank you for your answer. I get that notice even if there is no item in the menu an empty menu this is why I don’t get it. It is only happening if the taxonomy hierarchical is set to true, example below.
/**
Initialize Portolio
*/
function fwdupt_portfolio_init() {
/**
First we register taxonomy, then custom post type.
The order is important, because of rewrite rules.
*/
$args = array(
‘label’ => __(‘Portfolio Categories’, ‘fwdupt’),
‘singular_label’ => __(‘Portfolio Category’, ‘fwdupt’),
‘hierarchical’ => true,
‘public’ => true,
‘rewrite’ => true
);
register_taxonomy(‘fwdupt-category’, ‘fwdupt_portfolio’, $args);
I understood you but this is not something to pay for is just a bug that I am trying to figure it out, also other developers could be interested in this I am not the only one with this issue I can bet.
did you try to remove the menu item for this taxonomy and add them one more time, or even better to remove the menu and then make one again, while the hierarchy is set to true, as suggested in the first reply? does the error persist?
Yes I tried that. By the way I forgot to mention that this is happening only on the portfolio archive (the custom post type) page so if I access the portfolio slug this page is called archive-fwdupt_portfolio.php , it doesn’t has anything special in it the same code as the blog for example but still it trigger that notice when the menu is registered. Really wired bug makes no sense.
I tried to give different names to the taxonomy and custom post type it makes no difference or menu, makes no difference.