Tag Info

New answers tagged

1

There is no conditional tag for no results on a search page, but you can create yourself one. You basically just have to check the value of $wp_query->found_posts, if it is 0, returns false, any other value, returns true function is_search_has_results() { global $wp_query; $result = ( 0 != $wp_query->found_posts ) ? true : false; return ...


0

You have to create a php file named search.php. Inside that file, write the code below: <?php get_header(); ?> <?php if( have_posts() ) : while( have_posts() ) : the_post(); ?> <article class="entry"> <header class="entry-title"> <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ...


0

That sent me in the right direction. Here is what I have came up with. I decided to create a shortcode so I can drop this anywhere needed. Using the get_page_by_title() also allowed me to find posts even if their post type was hidden from the traditional search. function esm_search($atts) { extract(shortcode_atts(array( ...


1

It is actually pretty annoying to bend WP_Query for it. However there is convenient get_page_by_title() function that can do just that. Despite the name it allows you to pass other post types as third argument.


0

you don't need to add another function to get the search form. If you want to change the look of the search form or add another items you'll have to add the searchform.php to your theme. It could look like this: <form role="search" method="get" class="search-form" action="<?php echo home_url( '/' ); ?>"> <input type="search" ...


0

Alright, so I managed to pull it off thanks to @toscho! =D He gave me this link: Add class to before_widget for all widgets with a dropdown and a counter I kind of worked up through it. All I wanted to do was add one class "col-sm-4" from Bootstrap to the search widget. is_admin() || add_filter( 'dynamic_sidebar_params', 'wpse172754_add_widget_classes' ); ...


0

There is a plugin with which you can add more CSS classes and ID's to a widget. It's called Widget CSS Classes. Pretty handy, take a look: https://wordpress.org/plugins/widget-css-classes/


0

Hey you can add class in before_widget something like this if ( function_exists('register_sidebar') ) register_sidebar(array( 'name' => 'Your Widget Name', 'description' => 'Description of your widget', 'before_widget' => '<div class="container-top">', 'after_widget' => '</div>', 'before_title' ...


-2

I thing, you should use this code for filter the check box category <?php // cat 42=Laos cat 57=2-4Days <?php $my_query_1 = new WP_query(array('category__and' => array(42,57))); ?> <?php while ($my_query_1->have_posts()) : $my_query_1->the_post(); ?> <a href="<?php the_permalink() ?>" rel="bookmark" ...


-2

Try fetching as $_GET['category']. Then u can use it whichever way u like


2

The custom properties you refer to are dates which a stored in a custom table, and which are joined onto the query for events. At this point in time, when querying events, this table is only joined when only the 'event' post type is being queried. That is, you can search for events - but the dates are only pulled in if you are searching only for events. ...


6

I've never seen it done before but the logic of the PHP IF/ELSE should mean you could simply plug a new query in after the ELSE: if ( have_posts() ) : while ( have_posts() ) : the_post(); get_template_part ( 'templates/post', 'main' ); endwhile; else: $the_query = new WP_Query( $args ); if ( $the_query->have_posts() ) : while ( ...


0

The above works well I've run the similar code, but tie the title and excerpt together. But found it breaks when someone enters a space " " either at the beginning or end of a search query term. So Ive add this line: $keys = array_filter($keys); // Add Bold to searched term function highlight_results($text){ if(is_search() && !is_admin()){ $sr = ...


0

The concept of same meta field values being relative to each other isn't native to WordPress. On top of my head you could create second meta field, which would express that relativeness as a number. So president is 1, vice president 2 and so on. This would be a pain to adjust if the hierarchy changes in future though.


0

Use get_terms() to retrieve terms that match your search query like : $termsResult = get_terms( 'CUSTOM_TAXONOMY_NAME', 'search=SEARCH_QUERY' ); where, CUSTOM_TAXONOMY_NAME is your custom taxonomy and SEARCH_QUERY is the string which you are using to search for terms. Afterwards you can generate list like : if ( ! empty( $termsResult ) && ! ...


-1

I wanted to follow up and mention that between Rarst's suggestion (WP now saves to post_content_filtered any time a new "container" page is created or updated) and Relevanssi's ability to include wp_posts columns in search results, I was able to achieve the desired results. Thank you so much, Rarst! Edit: To kaiser's point, my answer does nothing to help ...


0

you could include the search term as a parameter in the URL that links to the page http://www.example.com/page-here/?search-highlight=frogs and then hook into the the_content filter to replace all instances of the search-highlight term with a highlighted version



Top 50 recent answers are included