adding more text to a query string

You can try and use set_query_var() very very early, before the query is parsed and queried for, for example during the pre_get_posts action. Although thinking about it, if you’re using pre_get_posts it’s likely easier to do something like this (off the top of my head): add_action( ‘pre_get_posts’, function( $query ) { if ( ! $query->is_main_query() … Read more

How to detect if the referer is 404 page?

Easiest and most robust way is to add a url parameter to the search so the search url will be something like http://www.example.com/?s=xyz&from404=1. Probably easiest way to do that is by adding a hidden field to the form. For “bonus points” use the browser’s history API to remove the parameter after the page load.

Exclude image url from search query

try this to exclude images from search. Add code to your functions.php: // Exclude images from search results – WordPress add_action( ‘init’, ‘exclude_images_from_search_results’ ); function exclude_images_from_search_results() { global $wp_post_types; $wp_post_types[‘attachment’]->exclude_from_search = true; }

Filtering custom posts by custom fields (ACF) [closed]

Ok, so after deeper research I’ve found out that values of some custom fields created by ACF are stored in MySQL database with some additional information like a:5:{i:0;s:6:”Aerial”;i:1;s:6:”Nature”;i:2;s:4:”Nude”;i:3;s:6:”People”;i:4;s:8:‌​”Wildlife”;}. This happens when a custom field can store multiple values (like chechboxes). So I’ve edited part of my query from this: if( !empty($_GET[‘theme’]) ) { $contestTheme = … Read more

How can I add search box in single.php?

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 esc_attr_e( ‘Skip to content’, ‘twentythirteen’ ); ?>”><?php _e( ‘Skip to content’, ‘twentythirteen’ ); ?></a> <?php wp_nav_menu( array( ‘theme_location’ => ‘primary’, ‘menu_class’ => ‘nav-menu’, ‘menu_id’ => ‘primary-menu’ ) … Read more

WordPress autocomplete search with taxonomies

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 json_encode($json); ?> Thanks milo for your help ! I needed … Read more

How to have multiple instances of the same taxonomy in a search form

jpd527, Please remember that ‘tag’ is singular and not plural. Here your form has multiple HTML element with same id so this is wrong. Now if you require to search data with two different inputs, then you can merge it via JS. HTML code like: <form method=”get” id=”search form” action=”https://wordpress.stackexchange.com/”> <div> <input type=”text” value=”” name=”tag_one” … Read more

Custom search SQL Query to add custom field in result

I got it ! Here is my final code for people who will search for similar problem 🙂 in functions.php : function se190254_custom_sql_for_search( ) { global $wpdb; //For security escape the search parameter $search_string = esc_sql($_GET[‘s’]); //Build the SQL request with $wpdb->base_prefix for “portability” $sql = “SELECT SQL_CALC_FOUND_ROWS {$wpdb->base_prefix}posts.ID FROM {$wpdb->base_prefix}posts LEFT JOIN {$wpdb->base_prefix}icl_translations t … Read more