Broken Page Link
-
I haven’t made any changes to my site, but my FAQ page link seems to be broken:
Error message is: Fatal error: Call to a member function get() on a non-object in /home3/leeannap/public_html/wp-includes/query.php on line 28
This FAQ page is embedded into my Cherry theme, so I’d hate to not use it and re-create another page.
-
How is that page generated? Is it an actual template file, or is it a standard ‘page’ with a shortcode added to it?
My best bet is that pre_get_posts or something is being used incorrectly on the page, or another possibly deprecated function is being used on the page and throwing the error.
Without the code from the template file, it will be hard to diagnose the issue.
Evan
Which PHP IDE do you use? I would suggest using an IDE for troubleshooting. But if you get a fatal error with “call to a member function get() on a non-object”, it means the object doesn’t exist and the variables haven’t been declared.
To troubleshoot your root causes, you need to print out all the global variables to find out the missing, undeclared variables
Add the following in query.php.
<?php
echo(“"); print_r($GLOBALS); echo("
“)
?>Thanks for the responses!
It is a template file and then I have a page that directs to the template:
<?php
/**
* Template Name: FAQs
*/get_header(); ?>
<div class=”motopress-wrapper content-holder clearfix”>
<div class=”container”>
<div class=”row”>
<div class=”<?php echo cherry_get_layout_class( ‘full_width_content’ ); ?>” data-motopress-wrapper-file=”page-faq.php” data-motopress-wrapper-type=”content”>
<div class=”row”>
<div class=”<?php echo cherry_get_layout_class( ‘full_width_content’ ); ?>” data-motopress-type=”static” data-motopress-static-file=”static/static-title.php”>
<?php get_template_part(“static/static-title”); ?>
</div>
</div>
<div class=”row”>
<div class=”<?php echo cherry_get_layout_class( ‘full_width_content’ ); ?>” id=”content” data-motopress-type=”loop” data-motopress-loop-file=”loop/loop-faq.php”>
<?php get_template_part(“loop/loop-faq”); ?>
</div>
</div>
</div>
</div>
</div>
</div><?php get_footer(); ?>
It looks like it has to do with the class full_width_content, is your page utilizing the full width template? Where is line 28 in the code? And did you try printing out the global variables ?
`<?php
echo(“
“);
print_r($GLOBALS);
echo(“
“)
?>Yes, it’s using full width FAQ template. I just spent the past half hour Googling how to print out my global variables…lol. No success. I have very limited coding knowledge which is why I don’t alter any code in my site.
I’m thinking one of my recent added plug-ins must have altered something. I’ve been deleting/deactivating with no luck.
I don’t know where line 28 is…can’t seem to figure out where it’s trying to pull from. The only related php files for this FAQ page is the above and this loop file:
<?php /* Loop Name: Faq */ ?>
<?php
// WPML filter
$suppress_filters = get_option(‘suppress_filters’);
if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
<div id=”post-<?php the_ID(); ?>” <?php post_class(‘page’); ?>>
<?php the_content(); ?>
<div class=”clear”></div>
</div><!–#post–>
<?php endwhile;
//query
$temp = $wp_query;
$wp_query = null;
$args = array(
‘post_type’ => ‘faq’,
‘showposts’ => -1,
‘suppress_filters’ => $suppress_filters
);
$wp_query = new WP_Query($args);if (have_posts()) : ?>
<dl class=”faq-list”>
<?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
<dt class=”faq-list_h”>
<h4 class=”marker”><?php echo theme_locals(“q”); ?></h4>
<h4><?php the_title(); ?></h4>
</dt>
<dd id=”post-<?php the_ID(); ?>” class=”faq-list_body”>
<h4 class=”marker”><?php echo theme_locals(“a”); ?></h4>
<?php the_content(); ?>
</dd>
<?php endwhile; ?>
</dl>
<?php else: ?>
<div class=”no-results”>
<?php echo ‘<p>‘ . theme_locals(“there_has”) . ‘</p>’; ?>
<p><?php echo theme_locals(“we_apologize”); ?> /” title=”<?php bloginfo(‘description’); ?>”><?php echo theme_locals(“return_to”); ?> <?php echo theme_locals(“search_form”); ?></p>
<?php get_search_form(); /* outputs the default WordPress search form */ ?>
</div><!–no-results–>
<?php endif;
$wp_query = null;
$wp_query = $temp;
?>Figured out which plug-in was messing up the page. It was “Connections”. Deleted it. Thank you for your help though!
The issue is not with the Connections plugin. The loops do not follow the correct method according the WordPress Codex:
https://codex.www.ads-software.com/The_Loop#Multiple_LoopsOne should never, ever, mess with the
$wp_query
global variable as things can and will break in quite unexpected ways.The lines causing the issue are ones that contain this:
$wp_query = null;
and this:$wp_query = new WP_Query($args);
.The latter should be something like this:
$new_query = new WP_Query($args);
and then the following loops should reference the$new_query
variable.Additionally after the loops end the
<?php wp_reset_query(); ?>
should be added per the Codex:https://codex.www.ads-software.com/Function_Reference/wp_reset_query
Hope that helps future users.
Hey LeeAnna
Glad you found the fix for it. I was gonna show you how to print out the global variables in PHP and suggest you to use Netbeans for your debugging next time.I took a look at the code for the CherryFramework… seems like this was a known issue that they fixed back on Dec 17. Looks like you should also update the framework.
https://github.com/CherryFramework/CherryFramework/commit/576b46f146d1f3820a74c65003e7afe7ac6ee942
- The topic ‘Broken Page Link’ is closed to new replies.