Edumar on "Remove Older and Newer posts and change Search tool for blank field"

ساخت وبلاگ

Dear Friends,

I'm several days making changes in my wordpress, and I got to solve a lot of them by searching in the Inteet.
But, I have two problems here that I could not solve. I found some very old solutions but that no longer work.

My home page is static page, and use the Twenty Eleven theme.

My questions are:
- When I do a blank search (Search widget), wordpress retus me a post with links stating "Older" and "Newer" posts.
I wish it did not retu anything, that something like "Nothing Found" (which appears when nothing is really found) or simply nothing happens.
I do not want it retuing any results when searching for blank or spaces.

- Another point: I did not want links options for the "Older posts" and "Newer posts". My goal is to do the search and present a single result (there will always be one to what I'm doing), no options to navigate by other posts.

Can someone help me? I have been discouraged to seek and test solutions that have not worked.

What did I already tried?

To avoid the older and newer links , I deleted the following lines of search.php file:

[ Moderator note: code fixed. Please wrap code in the backtick character or use the code button. ]

<? Php twentyeleven_content_nav ( ' nav -above ' ); ? >
<? Php twentyeleven_content_nav ( ' nav -below ' ); ? >

I know nothing about codes, I ventured to do this after reading something about the function "nav" .
It worked ! The links are gone .... but ..... That's right what I did ?

Is it correct?

To try to solve the Search problem I found a code in an website to be placed in functions.php.
It would do the function to make a blank search and instead of making wordpress go to the home page, it would go to a page with search results, if that's what I understood.
Interestingly, in my case, it does what I wanted (but not the idea of ​​this function), retuing any results:

function change_blank_search ($ query_variables) {
if (isset ($ _GET [ 's']) && empty ($ _GET [ 's'])) {
$ Query_variables [ 's'] = "";
}
retu $ query_variables;
}
add_filter ( 'request', 'change_blank_search');

Is that right for what I want or I created another mistake that I did not notice yet? What would be the correct format of this function to retu me "no results found"? Or leave anyway as it is running the risk of having created some other problem not realized yet?

I found this solution here: https://www.webhostinghero.com/fix-the-empty-search-homepage-problem-wordpress/

Did this work to me because I put this code to make searchs only in the titles of posts ?:

// Search SQL filter for matching against post title only.
function __search_by_title_only ($ search, $ wp_query)
{
global $ wpdb;
if (empty ($ search))
retu $ search; // Skip processing - the search term in query
$ Q = $ wp_query-> query_vars;
$ N =! empty ($ q [ 'exact'])? '', '%';
$ Search =
$ Searchand = '';
foreach ((array) $ q [ 'search_terms'] as $ term) {
$ Term = esc_sql (like_escape ($ term));
$ Search = "{$ searchand} ($ wpdb-> posts.post_title REGEXP '[[: <:]] {} $ term [[:>:]]').";
$ Searchand = 'AND';
}
if (! empty ($ search)) {
$ Search = "AND ({$ search})";
if (! is_user_logged_in ())
$ Search = "AND ($ wpdb-> posts.post_password = '')."
}
retu $ search;
}
add_filter ( 'posts_search' '__search_by_title_only', 1000, 2);

But I realized that if I type * or *. or *.* it also retus results ... very complicated it ... I do not know what to do.

Thank you very much for your help.

Eduardo

Please, sorry my poor English.

WordPress ...
ما را در سایت WordPress دنبال می کنید

برچسب : نویسنده : استخدام کار wpss بازدید : 242 تاريخ : سه شنبه 25 خرداد 1395 ساعت: 20:47