Tag Info

New answers tagged

1

You can use pre_get_posts to modify the main query, but you will need to create new queries for the other searches. Use get_query_var('s') to get the search terms and create new WP_Query objects to perform your search. Without more information it is hard to provide much more detail to the answer.


1

Try this and change the classes if needed. <div id="navbar" class="navbar"> <nav id="site-navigation" class="navigation main-navigation" role="navigation"> <button class="menu-toggle"><?php _e( 'Menu', 'twentythirteen' ); ?></button> <a class="screen-reader-text skip-link" href="#content" title="<?php ...


0

When we try searching for example.tld, then the default search query looks into the post title and content with: ... (wp_posts.post_title LIKE '%example.tld%') OR (wp_posts.post_content LIKE '%example.tld%') ... When we add an attachment or a local link, into the post content, we normally get the full url, for example: ...


0

Ok I got it! That's the code for my search-results.php <?php include('../../../wp-load.php'); $term=$_GET["term"]; $json=array(); $terms = get_terms( 'produits' ); if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){ foreach ( $terms as $term ) { $json[]=array( 'value'=> $term->name ); } } echo ...


5

You should be able to do that with: /** * Setup a custom hook before the second post on the search page */ add_action( 'the_post', function( $post, \WP_Query $q ) { if( $q->is_search() && $q->is_main_query() && 2 === $q->current_post ) { do_action( 'wpse_before_second_post_in_search' ); } }, 10, 2 ); /** * ...


1

This is not how pre_get_posts works. The pre_get_posts action gives developers access to the $query object by reference (any changes you make to $query are made directly to the original object - no return value is necessary). https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts What you are doing is simply wrong. You don't ...


0

iolocin, I took your edited answer and as Pieter Goosen mentioned, made sure it was an array in an array and as per the codex. Final working code: function wpse188669_pre_get_posts( $query ) { if ( ! is_admin() && $query->is_main_query() && $query->is_search() ) { $tax_query = array( ...


3

The problem with your approach is that woocommerces product category is a custom taxonomy called product_cat. But with cat you are addressing the built-in category. Taxonomies can be addressed with a tax query, simplified example below: function wpse188669_pre_get_posts( $query ) { if ( ! is_admin() && ...


0

In your index.php, you should have something a bit like: <?php if ( have_posts() ) : ?> <!-- HTML --> <?php while ( have_posts() ) : the_post() ?> <!-- Post content --> <?php endwhile ?> <!-- HTML --> <?php endif ?> You can extend this code to say "if no posts and is search, display ...


1

I have some recommendations for your question: First: stop using query_posts(). See the codex about this function to see why you shouldn't use it in themes or plugins. Anyway, if you are in a some weird situation where you have not option and you need to use query_posts(), you should run wp_reset_query() after the loop. You must know that you are using the ...


0

You have to run the loop , modify your search.php something similar to the code below <?php get_header();?> <div class="wapper"> <div class="contentarea clearfix"> <div class="content"> <ul> <?php if ( have_posts() ) : ?> <header class="page-header"> ...


0

You can modify any query in pre_get_posts filter. So your code could looks like this: function prefix_modify_search( $query ) { if( $query->is_search && $query->is_main_query() ) { $search = $query->get( 's' ); $search .= '*'; $query->set('s', $search); } } add_action( 'pre_get_posts', ...


1

If you check the documentation for WP_Query you will notice that post_count, which you are using, returns the number of posts being displayed. That is what you see, but not what you want. found_posts returns the total number of results for the query, which is what you want. $post_count The number of posts being displayed. $found_posts ...


0

One way to avoid empty search is to perform javascript check for empty value of the search field and if found field empty then stop submitting the search form like below: $('#searchform').submit(function(){ search_value =$.trim($('#searchform #s').val()); if(search_value == ""){ return false; // You can also pop a ...


0

If you have a "natural" artwork archive (typically setting has_archive to true in your register_post_type() arguments), you already have the functionality in place: http://example.com/artwork/?s=query ...assuming artwork is your archive slug, WordPress will search only artwork for "query". Just set the action attribute of the search form to the archive ...


0

You just need to get the data using get_post_meta(). <h1><a href="<?php echo get_permalink()?>"><?php the_title(); ?></a></h1> <span class="description"> <?php echo get_post_meta( get_the_ID(), 'mobile_adv_service_desc', true ); ?> </span> This Plugin stores your values as WordPress metadata. So to ...


-2

Put this in your custom search page instead of your code, and don't forget to define your post types in the query arguments.. <?php // Query arguments global $wpdb; // If you use a custom search form // $keyword = sanitize_text_field( $_POST['keyword'] ); // If you use default WordPress search form $keyword = get_search_query(); $keyword = '%' . ...


0

Try to apply some function like htmlspecialchars() on your query before searching for it, it will translate your special chars into HTML entities.


1

On a stock WordPress installation, WP_Query will default to post_type = 'post'. Consider this simple example: $args = array( "posts_per_page"=>5, "ignore_sticky_posts"=>true ); $itposts = new WP_Query( $args ); It will result in the following query to be executed: SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts WHERE 1=1 AND ...


0

One option is to use the pre_get_posts hook and check that the query is a search query: function my_theme_pre_get_posts( WP_Query $query ) { if ( $query->is_search ) { ... } return $query; } add_filter( 'pre_get_posts', 'my_theme_pre_get_posts' );


2

You can use the pre_get_posts hook. Do note though, this hook filters the query on both the front-end and admin. For example, we could do something like this: function search_post_types( $query ) { if( is_admin() ) { return $query; } if ( $query->is_search && $query->is_main_query() ) { $query->set( 'post_type', ...



Top 50 recent answers are included