Issue with theme


#1

Hi.

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?

Any help is appreciated.

Thank you.


#2

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;
}

Thank you.


#3

Hello,

If your purchase theme from themeforest which one you are customizing .

you can contact with your item author hope they will help you soon.

With your purchase key

Best way you can hire a freelancer hope he will solved your issue.
https://studio.envato.com/

Thanks


#4

I am building my own theme :slight_smile:


#5

Then this is the best way. hire a freelancer hope he will solved your issue.
https://studio.envato.com/

you can knock her @ki-themes she will help you (paid task).


#6

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.


#7

Every author is responsible to fixing their theme bug, error etc.
but they are not responsible to customize, installation etc.

Happy to hear that solved your issue.


#8

@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!


#9

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);

    /**

    • Register portfolio_project custom post type.
      */
      $args = array(
      ‘label’ => __(‘Portfolio’, ‘fwdupt’),
      ‘labels’ => array(
      ‘singular_label’ => __(‘Item’, ‘fwdupt’),
      ‘all_items’ => __(‘Items’, ‘fwdupt’),
      ),
      ‘show_ui’ => true,
      ‘public’ => true,
      ‘capability_type’ => ‘post’,
      ‘rewrite’ => array(‘slug’ => ‘portfolio’),
      ‘has_archive’ => true,
      ‘taxonomy’ => ‘fwdupt-category’,
      ‘menu_icon’ => ‘dashicons-portfolio’,
      ‘supports’ => array(‘title’, ‘editor’, ‘comments’, ‘page-attributes’)
      );
      register_post_type(‘fwdupt_portfolio’ , $args);
      }
      add_action(‘init’, ‘fwdupt_portfolio_init’, 1);

#10

hey @FWDesign this only registers your post type and a custom taxonomy to go with. here’re developer pages for both https://developer.wordpress.org/reference/functions/register_taxonomy/ and https://developer.wordpress.org/reference/functions/register_post_type/ I don’t think the error is here, also you might want to switch the ordering of your code here, first register the post type, then register the taxonomy for it, but this isn’t the error, as wp handles this well, but just codewise. so, you say the error is in the back-end while editing the nav menus? thanks!


#11

Sorry, I’m not agree with you.
I just informing to him that where he can get his solution.


#12

Indeed the error is not caused there it is caused when I register the menu

<?php if (has_nav_menu('primary')) { wp_nav_menu( array( 'theme_location' => 'primary', 'container' => 'nav', 'container_class' => 'primary-navigation' )); } ?>

If in the taxonomy I set ‘hierarchical’ => false the notice is not appearing anymore but I need it to be hierarchical.

Again thank you for your help. I appreciate it.


#13

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.


#14

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?


#15

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.