New answers tagged

2

You should use pre_get_post action to alter the search query. It is much better approach and you will avoid unnecesary queries (actually, with your code, WordPress already performed the database query for the current request but you discard it and perform a new database query). add_action( 'pre_get_posts', 'custom_search_query' ); function ...


4

Just an alternative to the informative answer by @PieterGoosen. After Pieter posted this part: if ( ! empty( $q['s'] ) ) { $search = $this->parse_search( $q ); } it came to mind that it might be possible to re-parse the search query, within the posts_search filter, for empty search string. But the parse_search() method is protected and even if we ...


3

I'm not sure if this is an intended bug or just a bug that was never anticipated, but it is definitely a flaw in design. This behavior exists in the following cases that I took note of before Setting an empty array to post__in returns all posts Passing an invalid term to a tax_query or using the name field with a name with special characters or more than ...


0

Ok after trying a bunch of different plugins, scripts, and custom coding, I've come across one that seems to be perfect! Only thing now is to figure out how to implement it in my site. My Solution


1

There are few issue with your code When using WP_Query in conjuction with the_post() or using get_posts() in conjuction with setup_postdata( $post ), you need to reset the $post global with wp_reset_postdata(), not wp_reset_query(). wp_reset_query() is used in conjuction with query_posts() which you should never ever use You would want to reset posdata ...


2

You could set up a custom post type with custom taxonomies and then allow people to filter the results or do a search. Failing that, perhaps an event plugin would help. It depends on how much coding you want to do or if you want to try and find a plug and play solution.


2

Wordpress comes preloaded with the scripts to do datepickers. If you dont want to do it with a plugin, create a regular text metabox, then you need to enqueue a custom script in the wordpress admin with jquery-ui and jquery-ui-datepicker dependencies: function enqueue_date_picker(){ wp_enqueue_script( 'field-date', ...


0

Found a solution that should work with all themes. function update_my_custom_type() { global $wp_post_types; if ( post_type_exists( 'post' ) ) { // exclude from search results $wp_post_types['post']->exclude_from_search = true; } } Found it from http://www.webtipblog.com/exclude-custom-post-type-search-wordpress/


2

I guess you mean overriding the post type of the main search query on the front-end. You could try: add_action( 'pre_get_posts', function ( WP_Query $q ) { if ( ! is_admin() && $q->is_main_query() && $q->is_search() ) $q->set( 'post_type', 'film' ); } ); This way you don't need a ...


0

You can add another loop.php with a different name: loop-film.php and edit it's query so as to retrieve only the film post type. Afterwards in your search.php call on your new loop: <h1><?php echo sprintf( __( '%s Search Results for ', 'site' ), $wp_query->found_posts ); echo get_search_query(); ?></h1> <?php ...


0

You can do this by editing the Search.php file in your theme. This file will contain something along the lines of this: <?php global $query_string; $query_args = explode("&", $query_string); $search_query = array(); foreach($query_args as $key => $string) { $query_split = explode("=", $string); $search_query[$query_split[0]] = ...



Top 50 recent answers are included