Wordpress modify returned search results - wordpress

When I search on my wordpress site I want to filter the search results, namely, I want to remove the first line of each search result.
However wordpress returns the text with all newlines removed, just a chunk of text, so I can not decipher where the new lines are removed.
I tried overriding the
function wp_trim_excerpt($text)
Function, but the $text passed there already has new lines removed. Can someone point me in the right direction of where/when this happens so I can modify the function?

It's removed because the loop.php will use the_excerpt() for searches and archives by default. Change it to the_content() or create / use your own custom function to return the search results in the format you want it in.

Related

Wordpress text editor input validation. Prevent save when certain characters are used on input

I'm trying to create a function on my theme's functions.php file that accomplishes that goal.
I want the editor to prevent saving or updating new posts when certain characters are used on the editor. Characters like non-breaking space, certain brackets and aposthrophes and encoded html entities.
I've managed to create a function to sanitize the input after the post was saved to the database, getting rid of all these undesired characters. I did this by writing a function that includes
$wpdb->update('wp_posts', ['post_excerpt' =>$sanitized_post_excerpt], ['id' => $post_id]);
and then adding the function as a hook to save_post:
add_action('save_post', 'sm_sanitize_HTML_entities', 99, 3);
Is there a way to prevent the input of the characters being saved (maybe even displaying a message to the user), rather than updating a sanitized version of the data after it's already been saved?
What da butt? enter code here
Blockquo [enter link description here][1]
Olá
[1]: https://%20xpt.

Wordpress PODS magic tags extend with parameters

I am wondering if there's any function that I can create in order to modify the magic tags behaviour.
Ideally, I would like to use a tag like this {#post_content|120} which would go through my custom function and check if there's a | character, then execute the original magic tag, while trimming text down to 120 characters.
But I don't know where to hook in order to filter this content.
I know that I can pass a function name with the magic tag but this isn't really helpful as I need to pass the characters limit parameter which PODS doesn't support.
Also, I can't be creating functions for all my characters limit as I have a lot of places where I need different limits and I would end up using tons of functions and no dynamic solution.
Can I somehow trigger a magic tag with a parameter? Any other thoughts about doing this another way?
Thank you!
I don't think that's possible, {#your_field, your_function} is how it works (the function takes the field value as input) - you could use different function names like trim_120, trim_100 and do the stuff you need in there - I guess it's to create excerpts with different length's although there are other ways to do that e.g use the_content filter for one ...

Passing variables in wordpress

I am having trouble with passing variables in my wordpress url. When i pass the variable and the value to the url, all is well
i.e.
mysite.com/product-part/?part=1/
but what i want is for the variable to be passed as follows:
mysite.com/product-part/1
In php, the normal way to pass variables to a url is:
mysite.com/?id=1
In wordpress, the above would look like this:
mysite.com/1
How can I achieve the above?
The Rewrite API lets you add create custom rewrite rules inside WordPress. You can call add_rewrite_rule() inside the "init" hook and give it a regular expression to translate into a query string. Something like:
function setup_rewrite_rules() {
add_rewrite_rule('^store/([0-9A-Za-z]+)/([0-9]+)/?', 'index.php?product_slug=$matches[1]&part=$matches[2]', 'top');
}
add_action('init', 'setup_rewrite_rules');
Note that the URL isn't an exact match for the existing product URLs because you need something that matches this regular expression.
You'll probably need to use a template_redirect handler to detect when these variables are set and show the normal product page since you're not using the product's normal permalink.
This is a very, very bad way to pass a variable. Wordpress uses "re-write" rules to determine what query to run. These "permalinks" identify, for instance, what post your are going to. In your example, using an integer such as "1", you could pass a variable by writing a re-write rule that said something like "all integers are a variable", or "all slugs that start with an integer are a variable" but you would soon get into conflicts with post names. What about posts that start with numbers, for instance? Also, many plugins would use permalinks to send you to certain pages, and you could come into conflict there. Better to use any of these things to pass variables:
get variables
post variables
hidden post variables
session variables
nonces
Wordpress meta-data like user meta data
Good luck

Wordpress, replace standard word /search

is it possible to replace the word search?
For example:
http://domain.com/search/helloWordl
to
http://domain.com/test/helloWordl
i think you just need to create a new page template and save as searchpage.php, add the correct code.
Change the form action to redirect to the page you just to create and that's it.
Read this to better understanding, you will find the correct loop and all the steps to do that.

What is the difference between get_the_* and the_* template tags in wordpress?

I am confuse about get_the_* and the_* template tags. I have used those many times to my theme but i am not clear enough when to use get_the_* and when to use the_* . Would you please explain both concept clearly.
Typically, there are two key differences between get_the_* and the_* functions.
get_the_* methods don't echo anything themselves. Instead, they return the value that you're interested in, normally as a string. For example, get_the_time() echoes nothing, and returns a string representation of the posting time of the current post. the_* methods directly output the same value, without you having to echo it; the_time() returns nothing, but directly echoes the posting time.
the_* methods are generally designed to be used inside the Loop, so they often don't take a parameter to specify which post you're asking about; for example, the_title() doesn't take a post_id parameter, and can therefore only act on the "current" post inside the Loop. It doesn't make sense to call it outside the loop—which post would it be getting the title for? However, get_the_title() takes a post ID as a parameter, so you can use it from anywhere to get the title of any post, as long as you've got the post's ID. (Many of the get_the_ methods take an optional post id parameter, and default to returning the value for the current post if they're used from in the Loop, for convenience.)
Because WordPress has been in development for so many years, and things have gradually been added, these aren't guaranteed rules, and you'll find exceptions here and there. You should take this as general advice and check the documentation for each specific instance as you need it.
The difference is that you can only use the_* inside your loop. But get_the* you can use inside or oustide the loop. Outside the loop you should give the post_id as a parameter.
And by default the_* echo's the title for example and get_the* just gets the title for using it in your PHP.
There is something more to it. I just tried the_content() and echo get_the_content() which should the same thing but.. If you add a filter('the_content') it wont work with echo get_the_content() but it works fine with the_content() method.

Resources