WordPress.org

Ready to get started?Download WordPress

Forums

Cannot Modify Headers - wp-includes/query.php:390 (4 posts)

  1. AphelionZ
    Member
    Posted 5 years ago #

    Hello all,

    I'm developing a plugin which makes use of the wp_redirect function. You can see the relevant code here:

    However, when I try to run that code I get this error.

    Cannot modify header information - headers already sent by (output started at /path/to.site/wp-includes/query.php:390) in /path/to/site/wp-content/plugins/post_shock/postshock_core.php on line 53

    Now, I checked query.php and nothing on line 390 seems to be creating any whitespace or sending any header info at all, so I suspect the problem might be deeper. Any ideas or thoughts would be appreciated!

  2. mrmist
    Forum Janitor
    Posted 5 years ago #

    I'd expect that an error is being thrown somewhere, hence causing the problem. Are you running with wp_debug enabled?

  3. AphelionZ
    Member
    Posted 5 years ago #

    Yeah, it's all notices and warnings based on some other plugins BUT that warning is one of them.

  4. AphelionZ
    Member
    Posted 5 years ago #

    I got it running now with no warnings, but it still doesn't redirect for some reason - and its not calling any errors! Here's the code in question:

    add_action('init', 'search_egg_redirect', 0);
    
    function search_egg_redirect() {
    	global $wpdb;
    	$query = $wpdb->prepare($_GET['s']);
    
    	if(!empty($query)) {
    		$term_row = $wpdb->get_row('SELECT term,page_id FROM pshock_searcheggs WHERE TERM="' . $query . '" LIMIT 1');
    		if($term_row->term) {
    			wp_redirect('http://google.com');
    		}
    	}
    }

Topic Closed

This topic has been closed to new replies.

About this Topic