[Support request] PHP Error with GP Pro Plugin on Custom Author.PHP Page

Home Forums Support [Support request] PHP Error with GP Pro Plugin on Custom Author.PHP Page

Home Forums Support PHP Error with GP Pro Plugin on Custom Author.PHP Page

Viewing 15 posts - 1 through 15 (of 21 total)
  • Author
    Posts
  • #1769438
    Thomas

    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!

    #1769448
    Leo
    Staff
    Customer Support

    Hi Thomas,

    Not sure if I fully understand.

    The error is pointing to a class-wp-query.php file in wp-includes folder which is a WordPress folder and not a theme folder.

    #1769552
    Thomas

    Yeah that’s whats confusing me, as the error goes away when GP Premium is disabled….

    #1769553
    Thomas

    Ohhhhh 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.

    #1769554
    Thomas

    Another 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 🙂

    #1769591
    Leo
    Staff
    Customer Support

    Do you get the error without your own author.php file?

    #1769625
    Thomas

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

    #1770593
    Tom
    Lead Developer
    Lead Developer

    Hi 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”?

    #1770819
    Thomas

    Hey 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 shows

    So it seems to be realted to the “Elements” module, strangely.

    #1771528
    Tom
    Lead Developer
    Lead Developer

    In 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?

    #1771552
    Thomas

    Hey 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.

    #1771927
    Elvin
    Staff
    Customer Support

    Hi 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?

    #1772573
    Thomas

    Same 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.

    #1773363
    Elvin
    Staff
    Customer Support

    Any 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/

    #1773376
    Thomas

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

Viewing 15 posts - 1 through 15 (of 21 total)
  • You must be logged in to reply to this topic.