Skip to Content
Menu

internal_suggestions()

Determine page suggestions on 404 pages.

PHP June 11, 2017

Usage

This function runs automatically, so it is not called manually. Is this incorrect?

Additional Notes

This function uses context clues from the requested URL to attempt to make suggestions for pages.

Was this page helpful? Yes No


    A feedback message is required to submit this form.


    Please check that you have entered a valid email address.

    Enter your email address if you would like a response.

    Thank you for your feedback!

    Source File

    Located in /libs/Functions.php on line 2768.

    No Hooks

    This function does not have any filters or actions available. Request one?
    PHP
            public function internal_suggestions(){
                if ( is_404() ){
                    $this->timer('Internal Suggestions');
                    $this->ga_send_exception('(PHP) 404 Error for requested URL: ' . $this->url_components()); //Track 404 error pages as exceptions in Google Analytics
    
                    $this->slug_keywords = array_filter(explode('/', $this->url_components('filepath'))); //Convert the requested filepath into an array (ignore query strings and remove empty items)
                    $this->slug_keywords = end($this->slug_keywords); //Get the last "directory" from the path (this was the requested "term" we will search for)
    
                    if ( !empty($this->slug_keywords) ){
                        //Query the DB with clues from the requested URL
                        $this->error_query = new WP_Query(array('post_status' => 'publish', 'posts_per_page' => 4, 's' => str_replace('-', ' ', $this->slug_keywords))); //Query the DB for this term
    
                        if ( function_exists('relevanssi_do_query') ){
                            relevanssi_do_query($this->error_query);
                        }
    
                        //Check for an exact match
                        if ( !empty($this->error_query->posts) && $this->slug_keywords === $this->error_query->posts[0]->post_name ){
                            $this->error_404_exact_match = $this->error_query->posts[0];
                        }
                    }
    
                    $this->timer('Internal Suggestions', 'end');
                }
            }
    

    Override

    This function can not be short-circuited with an override filter. Request one?