Tagged: 

Viewing 17 posts - 1 through 17 (of 17 total)
  • Author
    Posts
  • #755082

    Hi,

    I activated the search icon in the header menu on my page (link in private content)

    Now my problem is that it only searches in blog entries, not in the menu pages (Products, Industries, Solutions,…) Is there a way to enable this? Also when searching it would be nice if the search results within the menu pages would be showed first.

    Kind regards,

    #755329

    Hey net-files,

    You can try using this plugin to search additional pages within your site:

    https://wordpress.org/plugins/search-everything/ 

    or, you can try adding the following to functions.php:

    function wp_search_filter( $query ) {
        if ( $query->is_search ) {
            $query->set( 'post_type', array('post','page') );
        }
        return $query;
    }
    add_filter('pre_get_posts','wp_search_filter');

    Best regards,
    Jordan Shannon

    #756275

    Adding this function to my functions.php did not change anything, blog entries are still the only thing found by search. Also this link says “page not found”, but I think I got the right one.

    Update: Changes somehow didn’t apply, but as they did now, it works! Thanks for your help!
    Update: Is there a way to display the “pages” within the results first?

    • This reply was modified 7 years, 9 months ago by net-files.
    #756673

    Hi,

    I am glad the initial issue was able to be worked out for you.

    As for displaying the page results first, you can try adding this into functions.php:

    add_filter(‘posts_orderby’,’my_sort_custom’,10,2);
    function my_sort_custom( $orderby, $query ){
    global $wpdb;

    if(!is_admin() && is_search())
    $orderby = $wpdb->prefix.”posts.post_type ASC, {$wpdb->prefix}posts.post_date DESC”;

    return $orderby;
    }

    In the script above search results are ordered by post type in ascending order (e.g. page then post), and then ordered by post date in descending order.

    Best regards,
    Jordan Shannon

    #757121

    Hey Jordan,

    thanks for your answer! It seems like is_search() is never true for this specific search. There is another search on my webpage ( under /blog ) which responds to this.
    What I am looking for now is an equal function for my ajax_search_response to be checked before executing your code. Please go to my attached web page, the search I want to modify is in the header, while the search that is addressed by is_search() can be found under “Blog”.

    Kind regards,
    Andy

    #758064

    Hi,

    If I am understanding the above correctly, you are not receiving the correct results from the header search. Try our advanced search via SearchWp. See the documentation here.

    Best regards,
    Jordan Shannon

    #758278

    Hey,
    I think I was a bit inexplicit there. The search results are fine, but reply #756673 hasn’t worked yet.

    add_filter(‘posts_orderby’,’my_sort_custom’,10,2);
    function my_sort_custom( $orderby, $query ){
    global $wpdb;

    if(!is_admin() && is_search())
    $orderby = $wpdb->prefix.”posts.post_type ASC, {$wpdb->prefix}posts.post_date DESC”;

    return $orderby;
    }

    This did not work because it seems like in the if statement is_search() never comes out as true. Everything’s working properly, except posts still being displayed before pages.

    Sorry for the circumstances,
    kind regards,
    Andy

    #761252

    Hey!

    The “pages” post type should be included in the ajax search functionality by default. It’s probably not working because of a plugin or a custom modification in the theme. Did you modify any of the theme files? Did you test it while all plugins are deactivated?

    Please post the WP and FTP login details here so that we can check it further.

    Regards,
    Ismael

    #761254

    Hi!

    UPDATE: If you’re using the W P M L plugin, please add this filter.

    // Ajax Search Query & W P M L
    add_filter('avf_ajax_search_query', 'avf_modify_ajax_search_query', 10, 1);
    function avf_modify_ajax_search_query($search_parameters)
    {
    	$language = ICL_LANGUAGE_CODE;
    	parse_str($search_parameters, $params);
    	$params['lang'] = $language;
    	$search_parameters = http_build_query($params);
    	return $search_parameters;
    }

    Regards,
    Ismael

    #772302

    Hey,

    thanks a lot for you help. I have one more question regarding the search functionality. Everything works fine now, despite for example if you search for “Security”, the results show every page that contains “Security” and they are ordered by the release date of the page. It would make much more sense if a page named exactly like the search term would be on top of the results. Is there a way to achieve this? I did a long research on this, but it all ends up in “install this plugin to..” which I want to avoid.

    Best regards,
    Andi

    • This reply was modified 7 years, 8 months ago by net-files.
    #773633

    Hey!

    Please replace the filter above with the following code.

    // Ajax Search Query & W P M L
    add_filter('avf_ajax_search_query', 'avf_modify_ajax_search_query', 10, 1);
    function avf_modify_ajax_search_query($search_parameters)
    {
    	$language = ICL_LANGUAGE_CODE;
    	parse_str($search_parameters, $params);
    	$params['lang'] = $language;
    	$params['orderby'] = 'title';
    	$params['order'] = 'DESC';
    	$search_parameters = http_build_query($params);
    	return $search_parameters;
    }

    Best regards,
    Ismael

    #774047

    Thanks for the quick response, it worked perfectly! I didn’t know wordpress makes a difference between the name of the page (textfield on top of page editor) and the title field. Is there a way to actually make it pick the name of the page?

    Best regards,
    Andi

    #774814

    Hi!

    Is there a way to actually make it pick the name of the page?

    I’m sorry but I’m not sure what you mean by that. Could you please explain it a bit further? Or provide a screenshot from imgur or dropbox.

    Best regards,
    Ismael

    #779294

    Hey,
    In Screen 1 you can see that the first search result for “business” is the page “jobs” which I don’t get. The other thing is that I’m not sure what title wordpress search uses as criteria (Screen 2 vs Screen 3)

    best regards,
    andi

    #779557

    Hi,

    To get better search results you might want to consider a plugin that allows you more control. Here is some reading on the topic

    http://www.wpbeginner.com/showcase/12-wordpress-search-plugins-to-improve-your-site-search/

    If you need further assistance please let us know.
    Best regards,
    Victoria

    #779882

    Hey,

    thanks for the reply. Can you tell me one last thing? Do you use the standard search, searchwp or relevanssi on
    http://kriesi.at/themedemo/?theme=enfold ??

    best regards,

    andi

    #780289

    Hi!

    The demo is using the standard search if I am not mistaken.

    Regards,
    Ismael

Viewing 17 posts - 1 through 17 (of 17 total)
  • You must be logged in to reply to this topic.