• I love your plugin, it works almost perfectly but I need one feature: I want the search results to stay on the sub-page. I have sub page with a category, (eg.: site.com/category) I put the Custom Field Search here and when I send filter the form sends me to back the main page with the results.
    Is there a built in way to do this or do I have to fiddle in the code of the plugin somewhere (which I want to strongly avoid).

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author don benjamin

    (@dondon-benjamincouk)

    There’s nothing built into the plugin to allow this. It would be difficult to build as the ideal behaviour would be different with different themes.

    You could try adding the following to your functions.php file:

    
    function wpcfs_get_current_page_uri() {
        return $_SERVER['REQUEST_URI'];
    }
    add_filter('wpcfs_results_page', 'wpcfs_get_current_page_uri');
    

    This would cause the URL to remain the same after submitting the form. It probably isn’t what you need though, depending on your theme this is likely to either fail to show the search results, or to fail to show whatever it is you wanted from the sub-category.

    Failing that you could try adding the following:

    
    $wpcfs_saved_settings = [];
    
    // Record all the query settings before they are rewritten
    function wpcfs_store_query_settings($wpquery) {
            global $wpcfs_saved_settings;
            $wpcfs_saved_settings = array(
                    $wpquery->is_search,
                    $wpquery->is_home,
                    $wpquery->is_page,
                    $wpquery->is_singular,
                    $wpquery->query_vars['pagename'],
                    $wpquery->query_vars['page_id'],
                    $wpquery->query_vars['paged']
            );
    }
    
    // Restore all the settings to their saved values
    function wpcfs_restore_query_settings($wpquery) {
            global $wpcfs_saved_settings;
            //$wpquery->is_search = $wpcfs_saved_settings[0];
            $wpquery->is_home = $wpcfs_saved_settings[1];
            $wpquery->is_page = $wpcfs_saved_settings[2];
            $wpquery->is_singular = $wpcfs_saved_settings[3];
            $wpquery->query_vars['pagename'] = $wpcfs_saved_settings[4];
            $wpquery->query_vars['page_id'] = $wpcfs_saved_settings[5];
            $wpquery->query_vars['paged'] = $wpcfs_saved_settings[6];
    
    }
    
    add_action('parse_query', 'wpcfs_store_query_settings', 0);
    add_action('parse_query', 'wpcfs_restore_query_settings', 20);
    
    

    Again, depending on your theme this may help, but may break one or other sets of functionality. You can experiment with commenting out some of the lines in wpcfs_restore_query_settings to reset some values and not others. Let me know if there is a setting that works for you and I will consider adding it as an option in future releases.

    Plugin Author don benjamin

    (@dondon-benjamincouk)

    Just tested the previous code and realised it interacts badly with pagination.

    A better solution would be:

    
    function wpcfs_get_current_page_uri() {
        return get_pagenum_link();
    }
    add_filter('wpcfs_results_page', 'wpcfs_get_current_page_uri');
    
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘want the search results to stay on page’ is closed to new replies.