- This topic has 7 replies, 3 voices, and was last updated 7 months, 2 weeks ago by
Tom.
-
AuthorPosts
-
July 23, 2020 at 1:43 am #1373083
Matt
Hi there,
I am building a site on my localhost and I am trying to add in different logos to different pages. I am using code that I got from the Generatepress support forums and it is working, however I am getting an error at the top of the home page and only the home page, when using wp_debug. The message is not visible with wp_debug disabled.
The error is:
Notice: Trying to get property of non-object in XXXXX/wp-includes/class-wp-query.php on line 3994
Notice: Trying to get property of non-object in XXXXX/wp-includes/class-wp-query.php on line 3996
Notice: Trying to get property of non-object in XXXXX/wp-includes/class-wp-query.php on line 3998
Notice: Trying to get property of non-object in XXXXX/wp-includes/class-wp-query.php on line 3994
Notice: Trying to get property of non-object in XXXXX/wp-includes/class-wp-query.php on line 3996
Notice: Trying to get property of non-object in XXXXX/wp-includes/class-wp-query.php on line 3998I’m pretty sure it is due to me using ‘is_front_page()’ and ‘is_page(89)’ but I can’t work out why I only get the error on the home page. It is working fine and there is no error message on the page: is_page(89).
When I added in the second if statement in the align_add_logo_filters() function it doubled the error output.
The code I am including at the top of my functions.php is:
<?php /** * GeneratePress child theme functions and definitions. * * Add your custom PHP in this file. * Only edit this file if you have direct access to it on your server (to fix errors if they happen). */ include('includes/partials.php'); include('includes/hooks-n-filters.php');
The code in my ‘hooks-n-filters.php’ file is:
<?php global $post; //Swap Navigation logo on homepage for white one. //Build the filter but it will not work by checking the homepage as it needs to be parsed first if ( ! function_exists( 'align_change_navigation_logo_output' ) ) { function align_change_navigation_logo_output( $output ) { return sprintf( '<!--standard generatepress logo code-->', esc_url( 'Image_URL' ), esc_attr( apply_filters( 'generate_logo_title', get_bloginfo( 'name', 'display' ) ) ) ); } } if ( ! function_exists( 'align_change_navigation_logo_output_music_change' ) ) { function align_change_navigation_logo_output_music_change( $output ) { return sprintf( '<!--standard generatepress logo code-->', esc_url( 'Image_URL' ), esc_attr( apply_filters( 'generate_logo_title', get_bloginfo( 'name', 'display' ) ) ), esc_url( apply_filters( 'generate_logo_href' , home_url( '/' ) ) ) ); } } //add action to parse add_action( 'parse_query', 'align_add_logo_filters' ); function align_add_logo_filters() { if ( is_front_page() ) { add_filter( 'generate_navigation_logo_output', 'align_change_navigation_logo_output' ); } else if ( is_page( 89 ) ) { add_filter( 'generate_navigation_logo_output', 'align_change_navigation_logo_output_music_change' ); } }
Also if there is a smart way to combine the two filters ‘align_change_navigation_logo_output’ and ‘align_change_navigation_logo_output_music_change’ I would appreciate any hints/tips.
BTW awesome theme I use it a lot.
Cheers
July 23, 2020 at 3:18 am #1373167David
StaffCustomer SupportHi there,
can you provide a link to the site so we can see what the issue is?
You can edit your original topic and use the Site URL field to share the link privately.Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/July 23, 2020 at 3:59 am #1373205Matt
Hi, thanks for getting back to me so quickly!
I have uploaded it to a subdomain and shared the url with you. Interestingly I notice the error message has changed now it is not on my mamp localhost:
Notice: Trying to get property ‘ID’ of non-object in XXXXX/wp-includes/class-wp-query.php on line 3994
Notice: Trying to get property ‘post_title’ of non-object in XXXXX/wp-includes/class-wp-query.php on line 3996
Notice: Trying to get property ‘post_name’ of non-object in XXXXX/wp-includes/class-wp-query.php on line 3998
Notice: Trying to get property ‘ID’ of non-object in XXXXX/wp-includes/class-wp-query.php on line 3994
Notice: Trying to get property ‘post_title’ of non-object in XXXXX/wp-includes/class-wp-query.php on line 3996
Notice: Trying to get property ‘post_name’ of non-object in XXXXX/wp-includes/class-wp-query.php on line 3998
July 23, 2020 at 9:51 am #1373769Tom
Lead DeveloperLead DeveloperHi there,
Those notices would be coming from code that looks like this:
$post->post_title $post->ID
Basically, it’s saying you’re trying to get a property (
->post_title
) on a variable that isn’t an object ($post
).$post
is an object by default, but may not be called correctly in your code somewhere.I’m not seeing anything in the code you’ve shared that would output these notices.
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentJuly 23, 2020 at 10:26 am #1373815Matt
yeh, I’m really not sure why it is throwing the errors.
The code is working as expected on all pages including the homepage but it is only throwing the errors on the homepage. If I switch off wp_debug the site works perfectly but it is annoying knowing that there is that error. I have used the same code on another site in exactly the same way and didn’t receive an error.
The error disappears if I remove the if_page() statements which correlates with it being ‘class-wp-query.php on line 3994’.
To be honest it’s not even that complicated a site which is what is making it super frustrating.
Also do you know why it added in ‘get property ‘post_title’’ when i uploaded it to a sub domain but when it was on my localhost it said ‘get property of non-object ‘?
July 23, 2020 at 2:42 pm #1374042Tom
Lead DeveloperLead DeveloperWhat if you use the
wp
hook instead ofparse_query
?Wonder if the hook itself is causing the issue.
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentJuly 23, 2020 at 11:50 pm #1374359Matt
Yes, that was it! I changed the hook like you suggested and the error disappeared.
Thanks so much for taking the time to look at this problem, I super appreciate it:)
July 24, 2020 at 8:51 am #1374981Tom
Lead DeveloperLead DeveloperGlad I could help! 🙂
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-development -
AuthorPosts
- You must be logged in to reply to this topic.