New answers tagged search
2
Use array_unique()
<?php
foreach($users as $user) {
$states[] = get_cimyFieldValue($user->ID, 'STATE'); // Grabing their state from their profile page
}
$states = array_unique($states);
?>
<div class="state">
<input type="hidden" name="search_type" value="members">
<select ...
0
If you want to filter the post on the basis of taxonomy then you use 'tax_query'
to 'wp_query'
eg:
$args = array('post_type' => array('custom_post_type_1','custom_post_type_2')
'numberposts' => -1,
'posts_per_page'=> 10,
'paged' => $paged,
'tax_query'=>array('relation'=> 'OR/AND'
...
0
If you look at the $wpdb->posts table in the database, you will notice that the file names, minus the file type ending, are used for the post_title for attachments. This means that you can effectively search the file name if you can get your search function to search attachments, which the default search (almost) already does.
In your code, these two ...
0
First, don't use query_posts.
Second, you can pass an s parameter to get most of the way there.
$program_search = 'test';
$args = array(
'post_type' => 'program',
's' => $program_search,
'meta_query' => array(
array(
'key' => 'keywords',
'value' => $program_search,
'compare' => 'LIKE'
),
)
);
$t = ...
1
Your issue is with the modification to the site search. You need to restrict your filter more. To prevent it executing on the backend add a negated is_admin() condition.
add_filter( 'pre_get_posts', 'tgm_cpt_search' );
function tgm_cpt_search( $query ) {
if ( !is_admin() && $query->is_search )
$query->set( 'post_type', array( 'page') ...
1
You can limit your query even further...
if (
!is_admin()
&& $query->is_search()
&& ($query->get('post_type') == 'yourposttype')
) {
// ...
But if you want to query all post types but restrict those results for only one post type in the same query, you can't do that. You would need a UNION statement, probably, and WP_Query ...
0
Yeah that theme is wrong. I just installed it myself. The excerpt() takes no parameters according to the codex.
Other alternatives are:
Add the link your self.
< a href =" < ?php the_permalink();" >My text here< /a>
Switch from using the excerpt function to the content() function.
< ?php the_content("My Text Here"); ?>
If you use ...
0
Filter 'the_excerpt' on the search page only:
add_filter( 'the_excerpt', 'wpse_99415_search_excerpt' );
function wpse_99415_search_excerpt( $excerpt )
{
if ( ! is_search() )
return $excerpt;
global $post;
// create a custom excerpt
return $custom_excerpt;
}
1
This is a bug in the theme. The real function does indeed not use the parameter:
/**
* Display the post excerpt.
*
* @since 0.71
* @uses apply_filters() Calls 'the_excerpt' hook on post excerpt.
*/
function the_excerpt() {
echo apply_filters('the_excerpt', get_the_excerpt());
}
PHP will just ignore it, but the unnecessary gettext call should be ...
0
There is also thisWP module that offers some of the Views functionality:
http://wordpress.org/extend/plugins/query-wrangler/
0
It turns out the free Relevanssi plugin does this rather well. I was afraid it would only search posts and not custom post types, but it does it all... and rather well! It only requires a simple filter added to your theme's functions.php file to get it to omit the body content:
// search titles only (relevanssi plugin)
add_filter('relevanssi_index_content', ...
2
I am not going to write your form for you, but create a form and submit it to a page to do the processing, or use the AJAX API. Then use WP_User_Query to actually search for users. It is a very WP_Query-like class that should let you do everything you want including search for user metadata from the $wpdb->usermeta table by passing a meta_query parameter ...
0
I am not sure what you mean by "the actual name". If you need the class name, look in the source of the theme for extends WP_Widget. Other widget information is stored in the $wpdb->options table under keys starting with widget_. Once you find that you can use get_option( 'widget_name' ); to get information about active widgets, including the "instance" ...
0
Add the "Search Everything" Plugin.
http://wordpress.org/extend/plugins/search-everything/
0
add this code to funtions.php
/// Search by Post Title
function search_by_title_only( $search, &$wp_query )
{
global $wpdb;
if ( empty( $search ) )
return $search; // skip processing - no search term in query
$q = $wp_query->query_vars;
$n = ! empty( $q['exact'] ) ? '' : '%';
$search = '';
$searchand = '';
foreach ( ...
0
Why not create a form that submits direct to Google? This would be the simplest solution (assuming you want to search every website in the world):
<form action="http://www.google.com/search" method="get">
<input type="text" name="q" placeholder="Search Google"/>
<input type="submit" /></form>
I believe that would do the job you ...
0
Use a Year-Month-Day notation for dates that allows numerical sorting. YYYMMDD is the most common choice.
Example
May 7, 2013 would be entered as 20130507.
May 3, 2013 would be entered as 20130503.
March 12, 2013 would be entered as 20130314.
A numerical sort of those dates would yield either 20130314, 20130503 and 20130507 or the reverse depending on ...
2
You'll likely need to your the $wpdb object. Learn about it on the WordPress Codex.
Check out the Custom Database Tables series on WPTuts+ as well. Lots of really good information about when to use custom database tables, and how to access them efficiently, securely and with WordPress best practices. The series should teach you everything you need to know.
0
WP search is rather simplistic. After some processing on search query, it adds condition to SQL query looking for LIKE (contains) match in title or post content.
So natively assigned taxonomies are not searched.
So you will either have to use additional code (or third party plugin) or use third party search solution (Google Custom Search Engine is rather ...
3
You can try running the function early so that it runs before the more link is created.
add_filter('the_excerpt', 'highlight_search_term',1);
add_filter('the_title', 'highlight_search_term');
But I don't think that solves the deeper problem, even if it were to work. That function is pretty crude and it will replace inside URLs and inside tag attributes, ...
0
Ok I have figured it out; added the following to functions.php:
add_filter( 'posts_request', 'my_request_filter', 10, 2 );
function my_request_filter($sql, $query) {
if($query->is_main_query() && is_search()) {
$sql = "SELECT * FROM wp_posts WHERE post_content LIKE '[smoothslider%' AND post_parent !='0'";
}
return $sql;
}
I ...
1
Modify the searchform.php, or create one in a child theme (recommended), and you should be able to modify the form all you want.
This is the file that get_search_form looks for and is the file used by the default search widget, though it is not listed in the Template Hierarchy.
Reference:
http://codex.wordpress.org/Function_Reference/get_search_form
1
Confusingly WordPress does not have a concept of a simply search page, it only has concept of search results page. The difference is critical because search without search query 404s as you are seeing.
If you want dedicated search page you would have to implement it as custom one, see Codex > Creating a Search Page.
0
I don't have your slider installed so I can't test this but something like the following is what you need:
function get_parent_page() {
if (is_singular()) {
global $wpdb,$post;
if (isset($post->ID)) {
$slide = $wpdb->get_var("SELECT DISTINCT slide_id FROM {$wpdb->prefix}smooth_slider WHERE post_id = {$post->ID} LIMIT 1");
...
1
This is what i did:
I run another query without pagination like this:
$newQuaryVars = '&posts_per_page=99999999999999&post_type=post';
$posts = query_posts($query_string .$newQuaryVars);
$categoriesList = array();
$categoriesAmounts = array();
Then in the while have posts i did the following:
while ( have_posts() ) : the_post();
...
0
It is easy to get the number of posts in a category...
$qry = new WP_Query(array('cat'=>2));
var_dump($qry->found_posts);
... but you could very easily have a lot of queries that way. Maybe something like this would help reduce that:
$catid = 1;
$qry = new WP_Query;
$cat_count = array();
if (!isset($cat_count['cat-'.$catid])) {
...
0
Here is one idea using the posts_clauses filter:
function search_posts_clauses($clauses, $query){
if(!is_admin() && $query->is_main_query() && $query->is_search()){
global $wpdb;
// replace post_content with meta_key and meta_value:
$searchterms = explode(" ",get_query_var("s"));
...
0
*haha* That one is actually pretty funny. You literally did shoot yourself in the foot.
Have a look at the source-code link-template.php line 1922 says:
if ( ! empty( $path ) && is_string( $path ) && strpos( $path, '..' ) === false )
The last condition strpos( $path, '..' ) is actually matched by the .'etc... etc...' in your example. The ...
1
I suggest you use <input type="submit" /> or <button type="submit" />.
<input type="button" /> is valid but doesn't submit the form by default (without you adding any ajax/js magic to it.
0
Plugin should never rely on a specific markup for the form. The only part that can be implied is the name of the search field: s. I don’t think any good plugin would break if you use a button.
I have written themes without any submit button; and nothing was broken.
1
You might try to use the posts_search filter as elegantly suggested by @Kaiser in the first link you provided. Here is one idea:
function filter_search($sql){
global $wpdb;
if( strpos(get_query_var("s"),"lass") !== false AND strpos(get_query_var("s"),"class") === false ){
$sql .= " AND {$wpdb->posts}.post_title NOT LIKE '%class%'";
...
-1
AHA!
Thanks for your help. You didn't post this as your direct answer but by giving me the HttpFox error I was able to track down a line in the admin-ajax file which defaulted the WP_ADMIN to true. By changing it to false it now works. Thanks very much.
4
That plugin uses the AJAX API as it should...
http://frome.fm/wp-admin/admin-ajax.php?s=ho&action=dwls_search
... but when not logged in that request fails (from HttpFox)...
07:23:58.923 0.155 470 0 GET (Aborted) NS_BINDING_ABORTED http://frome.fm/wp-admin/admin-ajax.php?s=ho&action=dwls_search
Since you say that the plugin works when ...
1
This is my Solution, I used Onclick attributes for the radio buttons to change the 'actions' of elements within the form.
<form id="searchme" action="<?php echo site_url(); ?>/postersearch" method="get">
<ul class=" four columns inline-list offset-by-one">
<li><label for="radio4"><input name="post_type" CHECKED ...
Top 50 recent answers are included