Fatal Error


#1

Hi I’m running a WordPress blog site and added the following code to the functions.php page and clicked view page.

//call a function just before the query runs to fetch posts
add_action(‘pre_get_posts’,‘change_post_type’);

function change_post_type($var) {
if(is_category()) {
$var->query_vars[‘post_type’] = ‘any’;
//it will change the value to ‘any’ from the default value of ;post’;
//can be any, attachment, page, post, or revision.
//‘any’ retrieves any type except revisions.
}
}

I got the following error!

Fatal error: Cannot redeclare change_post_type() (previously declared in /home/julwre/WiredVoltage.com/wp-content/plugins/map-categories-to-pages/map-categories-to-pages.php:72) in /home/julwre/WiredVoltage.com/wp-content/themes/ifeature/functions.php on line 349

I FTP’d to my Dream Host directory and tried to open the file but got the following error:

550 /WiredVoltage.com/wp-content/themes/ifeature/’. get_template_directory_uri() .’/images/home.png: No such file or director

I was assuming I would be able to open the file to undo the changes I made earlier?

Please help

Many thanks


#2

First, in PHP function names must be unique.

Second it appears you tried to pass PHP code as the filename to the FTP program.


#3

The code should be this:

//call a function just before the query runs to fetch posts
add_action('pre_get_posts','wiredvoltage_change_post_type');

function wiredvoltage_change_post_type($var) {
if(is_category()) {
$var->query_vars['post_type'] = 'any';
//it will change the value to 'any' from the default value of ;post';
//can be any, attachment, page, post, or revision.
//'any' retrieves any type except revisions.
}
}

Which file are you editing?

/home/julwre/WiredVoltage.com/wp-content/themes/ifeature/functions.php

That should still work if you download it from FTP.