Tagged: ismael
-
AuthorPosts
-
March 3, 2017 at 2:43 pm #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,
March 3, 2017 at 8:22 pm #755329Hey 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- This reply was modified 7 years, 8 months ago by Jordan Shannon.
March 6, 2017 at 10:13 am #756275Adding 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, 8 months ago by net-files.
March 7, 2017 at 12:36 am #756673Hi,
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- This reply was modified 7 years, 8 months ago by Jordan Shannon.
March 7, 2017 at 5:13 pm #757121Hey 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,
AndyMarch 8, 2017 at 10:49 pm #758064Hi,
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 ShannonMarch 9, 2017 at 10:23 am #758278Hey,
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,
AndyMarch 15, 2017 at 9:54 am #761252Hey!
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,
IsmaelMarch 15, 2017 at 9:59 am #761254Hi!
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,
IsmaelApril 5, 2017 at 8:28 am #772302Hey,
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, 7 months ago by net-files.
April 7, 2017 at 2:45 am #773633Hey!
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,
IsmaelApril 7, 2017 at 3:56 pm #774047Thanks 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,
AndiApril 9, 2017 at 8:36 am #774814Hi!
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,
IsmaelApril 18, 2017 at 1:56 pm #779294Hey,
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,
andiApril 18, 2017 at 6:50 pm #779557Hi,
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,
VictoriaApril 19, 2017 at 10:40 am #779882Hey,
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
April 20, 2017 at 5:35 am #780289 -
AuthorPosts
- You must be logged in to reply to this topic.