I’ve installed WordPress on top of wordpress many times, through SVN and replacing folders… The database remained always the same. Suddenly a fresh copy from SVN can’t work in two different machines with the following code, from wp survey and quiz tool:
function wpsqt_main_site_quiz_page($atts) {
extract( shortcode_atts( array(
'name' => false
), $atts) );
if ( !$name ){
require_once WPSQT_DIR.'/pages/general/error.php';
}
require_once WPSQT_DIR.'/includes/site/quiz.php';
ob_start();
wpsqt_site_quiz_show($name);
$content = ob_get_contents();
ob_end_clean();
return $content;
}
add_shortcode( 'wpsqt_page' , 'wpsqt_main_site_quiz_page' );// Deprecated and will be removed
add_shortcode( 'wpsqt_quiz' , 'wpsqt_main_site_quiz_page' );
If I use echo to see where the code is being reached, add_shotcode is being reached while inside the function is not and the page just displays this:
[wpsqt_quiz name="test"]
Instead of replacing it with the expected quiz.php.
Now I just deleted the database got a fresh install of wordpress and the plugin, and of course everything worked fine. If I get the SVN version, which isn’t all that modified (it just got 1 plugin – Magic Fields – and a customized theme), remove the plugin and install it again, it still doesn’t work!
What could be going wrong here? What is everything needed to make add_shortcode work?
That problem had been bugging me since yesterday. Finally found out the reason, (now) obviously on the customized template.
The header included a call to
query_posts, which supposedly can only be called once per page load. Then there comeswp_reset_queryto rescue. But wait! Seems like both of those functions are deprecated and neither should be used! Instead, we should always use WP_query object.So, this works but it’s wrong:
and this is the right and proper way:
Without that, the subsequent query_posts on the page itself are not properly loaded and thus the
[wpsqt_quiz name="test"]inside them (in the page post) is never called.Also, it seems like
[wpsqt_quiz name="test"]can’t be added to the template page.That’s all.