- This topic has 20 replies, 4 voices, and was last updated 2 years, 11 months ago by Elvin.
-
AuthorPosts
-
May 7, 2021 at 10:59 am #1769438Thomas
Hey GP Team.
I have a weird error occuring. I am currently receiving this following notice when I have GP Premium enabled on my Author.php custom file:
Notice: Undefined offset: 0 in /home1/monadno7/public_html/staging/wp-includes/class-wp-query.php on line 3300
I have tried disabling every other plugin and the error isn’t there until I activate GP Premium :(.
Hoping you all could give a clue as to a solution!
Here is the code of my Author.PHP file, so it could be something in there, although it is quite basic:
<?php /** * The template for displaying Archive pages. * * @package GeneratePress */ if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } get_header(); ?> <div id="primary" <?php generate_do_element_classes( 'content' ); ?>> <main id="main" <?php generate_do_element_classes( 'main' ); ?>> <?php /** * generate_before_main_content hook. * * @since 0.1 */ $curauth = (isset($_GET['author_name'])) ? get_user_by('slug', $author_name) : get_userdata(intval($author)); do_action( 'generate_before_main_content' ); echo ('<div class="customAuthorPage">'); echo ('<p>' . esc_attr($curauth->nickname) . '</p>'); echo('</div>'); $args = [ // parameters go here ]; $query = new WP_Query( $args ); if ( $query->have_posts() ) { while ( $query->have_posts() ) { $query->the_post(); // display the post the_title(); the_content(); } wp_reset_postdata(); } else { esc_html_e(''); } /** * generate_after_main_content hook. * * @since 0.1 */ do_action( 'generate_after_main_content' ); ?> </main> </div> <?php /** * generate_after_primary_content_area hook. * * @since 2.0 */ do_action( 'generate_after_primary_content_area' ); get_footer();
Thank you for the help!
May 7, 2021 at 11:10 am #1769448LeoStaffCustomer SupportHi Thomas,
Not sure if I fully understand.
The error is pointing to a
class-wp-query.php
file inwp-includes
folder which is a WordPress folder and not a theme folder.May 7, 2021 at 1:03 pm #1769552ThomasYeah that’s whats confusing me, as the error goes away when GP Premium is disabled….
May 7, 2021 at 1:05 pm #1769553ThomasOhhhhh I think I might’ve figured it out.
So I have a custom element that assigns the Featured Image as a page header along with a fallback. Since author.php (and by extension archive.php) don’t have featured image capability, I think it sends this error along.
May 7, 2021 at 1:09 pm #1769554ThomasAnother update, sorry for the many posts in a row.
So, I figured creating a new header JUST for the archives without setting it to look for a Featured Image would solve this, but it didn’t. Even without a image in the header it still throws this error/warning. I’m not sure what’s causing it, but if you know anything or if I figure it out i’ll send a notice 🙂
May 7, 2021 at 2:10 pm #1769591LeoStaffCustomer SupportDo you get the error without your own
author.php
file?May 7, 2021 at 2:54 pm #1769625ThomasHey Leo, nope, it does appear to only be related to the WP Users archives and author.php. Although, I don’t have any other archive files I think to test. Although, the error doesn’t pop up when I load the administrators profile page, just anyone else. So something to do with users then I presume!
May 8, 2021 at 10:33 am #1770593TomLead DeveloperLead DeveloperHi there,
Not sure why GP Premium would have anything to do with this. What happens if you deactivate all of the modules in “Appearance > GeneratePress”?
May 8, 2021 at 7:15 pm #1770819ThomasHey Tom, getting the obvious out of the way in that disabling Elements gets rid of it, I found the following:
Backgrounds: Error still shows
Blog: Error still shows
Colors:Error still shows
Copyright: Error still shows
Disable Elements: Error still shows
Menu Plus: Error still shows
Secondary nav: Error still shows
Typography: Error still showsSo it seems to be realted to the “Elements” module, strangely.
May 9, 2021 at 10:03 am #1771528TomLead DeveloperLead DeveloperIn that case, it’s likely you’ve added some code inside of an Element that’s causing the error.
What happens when you “Draft” each element?
May 9, 2021 at 10:16 am #1771552ThomasHey Tom
When I draft the element, the error goes away (and so does the header).
Currently I have the header set up like this:
<!–comment–!>
But even if I change it to something like <h1>test</h1> the error would come back. If I put nothing in the text / html area, the error goes away (but so does the header image).
I can just custom code a header into this, just figured i’d give you a heads up, although maybe this issue is relegated to just me lol.
May 9, 2021 at 9:24 pm #1771927ElvinStaffCustomer SupportHi there,
On your author.php template, what happens if you temporarily remove this line?
$curauth = (isset($_GET['author_name'])) ? get_user_by('slug', $author_name) : get_userdata(intval($author));
and these.
echo ('<div class="customAuthorPage">'); echo ('<p>' . esc_attr($curauth->nickname) . '</p>'); echo('</div>');
Can you test again if the error occurs when you add any element?
Also,
Can you include the
$args
values?May 10, 2021 at 6:12 am #1772573ThomasSame error still shows up :(. Here’s my query:
$args = [ // parameters go here ]; $query = new WP_Query($args); if ($query->have_posts()) { while ($query->have_posts()) { $query->the_post(); // display the post the_title(); the_content(); } wp_reset_postdata(); } else { esc_html_e(''); }
There’s another interesting case of a 0 showing up that I can’t explain. In the private area I have included a link but if you run a search you’ll get a result, but then a random “0” at the end. I doubt its related but it might give a clue? But I don’t think that is GP related.
May 10, 2021 at 4:42 pm #1773363ElvinStaffCustomer SupportAny reason why your WP_query arg is empty?
I believe that’s where the error is coming from.
Set your args appropriate to the author page. https://developer.wordpress.org/reference/classes/wp_query/
May 10, 2021 at 5:07 pm #1773376ThomasWas using author.php more as a template then actually seeing any of the posts, so that’s why it was left empty, if that makes sense!
Unfortunately that didn’t do it either :(. I tried it a couple of ways:
$args=[ 'author' = $authorID ]
and tried it like this:
$query = new WP_Query(array('author'=>$authorID));
but it might just be a glitch with the query itself and this page? Because I tried to pass some content into the while haveposts loop and nothing showed up; similiary if I remove the wp_query, the page still works, the error is still there.
So i’m not sure lol. Do you folks have a author.php page you used that I could experiment with? Even if its just boilerplate.
Thanks!
-
AuthorPosts
- You must be logged in to reply to this topic.