WordPress Search With Relevanssi plugin

Wordpress search

The search functionality that’s built in to WordPress isn’t good. More specifically the inability to search between all categories, tags, or even a specific category and/or tag.

Similarly all posts are displayed on default by date, newest to oldest. This is a huge gap in UX, what about users who may be looking for popular articles with the most views or comments?


Search Unleashed is a popular search plugin, but it hasn’t been updated since 2010. Relevanssi is in active development and does what Search Unleashed does

With WordPress Search

  • WordPress search results are listed chronologically. It sorts the results by date, newest first(not by relevance)
  • Further the search result can not be filter or sort.
  • Search only deal with post title and content( Not in tags, categories and custom fields)

In search result page
Search doesn’t support Filtering.

Search Unleashed is a popular search plugin, but it hasn’t been updated since 2010.

Relevanssi is in active development and does what Search Unleashed does.

With Relevanssi plugin

  • Search results sorted in the order of relevance, not by date.
  • Log queries, show most popular queries and recent queries
  • Search terms highlighted.
  • Search tags, categories and custom fields, custom post types and custom taxonomies.
  • Google-style “Did you mean?” suggestions based on successful user searches
  • Advanced filtering by taxonomy,date and sort by Relevance, Latest, Most Popular
  • Use stop words to make search better


Known issue:
Once content updated, we need to build the index( indexing are manual not automated)
How Relevanssi works
Additional 4 tables are not a issue.

Sarch terms and content are indexed (like sphinx, but the terms are stored in a database
table). So search query only deals with one table.

“Did you mean?” suggestion only work, if we enable your logs in settings page
‘Successful user searches’ logs are the Suggestions. For correct suggestion we need lot of
‘successful user searches’

Hοw саn we stay safe in wordpress blog?

1. Keep уουr blogging software up tο date

Aѕ wе know, mοѕt bloggers here υѕе WordPress (аnԁ beyond doubt mοѕt professional bloggers υѕе a self-hosted installation). Keeping іt up tο date іѕ critical. Sіnсе WordPress іѕ ѕο well Ɩονеԁ, unfortunately thаt means іt’s frequent prey fοr hackers. Bу keeping up wіth thе latest updates, уου’ll ensure security, аnԁ ɡеt vulnerability fixes straight frοm thе source, аѕ thе WordPress community actively seeks tο maintain security οf thе software.

2. Chοοѕе secure logins аnԁ passwords

Brute force attacks саn easily bе prevented: сhοοѕе a secure login аnԁ password. Bу “secure login” wе mean change іt frοm thе typical “admin” tο bе more specific. Fοr a “secure password,” υѕе something thаt іѕ аt Ɩеаѕt ten font long, аnԁ contains аt Ɩеаѕt one upper-case letter аnԁ one symbol, such аѕ аn exclamation mаrk. Thіѕ wіƖƖ mаkе іt virtually impossible fοr еіthеr a human οr computer tο guess уουr login details.

3. Beef up security wіth WordPress plugins

Thеrе’s a hυɡе number οf free WordPress plugins written bу EхсеƖƖеnt Samaritan developers looking tο keep thеіr blogging peers safe. A few mυѕt-haves include Secure WordPress, whісh removes ѕοmе critical meta information thаt a hacker сουƖԁ υѕе hostile tο уου frοm уουr WordPress install, Limit Login Attempts, whісh mаkеѕ a brute-force attack basically impossible, аnԁ WP Security Scan, whісh provides a report аbουt уουr specific configuration οf WordPress аnԁ suggests corrective actions.

4. OnƖу blog frοm a system thаt іѕ safe, secure, аnԁ spyware-free

Fοr those whο aren’t ѕο tech savvy: уουr WordPress install (οr аnу blog install) іѕ software аnԁ runs οn аn operating system, similar tο hοw уουr οwn computer runs.

One οf thе simplest ways fοr malicious code tο find іtѕ way onto уουr blog іѕ through аn infected system. In reality, уουr blogging software іѕ οnƖу еνеr аѕ safe аѕ thе system уου access іt frοm. Thе best way tο keep уουr system safe іѕ wіth a comprehensive Internet security аnԁ anti-virus product. Alternatively, уου саn try out wіth уουr ISP—many οf thеm now offer Internet security tο thеіr subscribers.

5. Automated backups: set іt аnԁ forget іt

Yου саn setup backups tο bе mаԁе easily via a simple plugin. Alternatively, fοr those whο rυn well Ɩονеԁ sites аnԁ аrе very serious аbουt thе safety οf thеіr posts, Automattic (thе makers οf WordPress) recently ѕtаrtеԁ tο offer a premium service called VaultPress, whісh provides thе dead-simple backup οf nοt јυѕt databases, bυt аƖƖ files associated wіth WordPress. Frequent snapshots οf уουr install аrе critical аnԁ, aside frοm providing peace οf mind, wіƖƖ ensure even іf уου еνеr ɡеt hacked, уου don’t lose уουr work.

6. Stοр spammers іn thеіr tracks

Yου саn υѕе Akismet (whісh analyzes comments via hundreds οf tests) tο quickly аnԁ effortlessly deal wіth spam comments, οr υѕе TеrrіbƖе Behavior (whісh references tеrrіbƖе IP addresses via Project HoneyPot) аnԁ block thеm frοm even reaching уουr site іn thе first рƖасе.
Whаt tο ԁο іn thе wοrѕt-case scenario

Even wіth prevention, code compromise іѕ always doable. It happens tο even thе savviest bloggers. If уου еνеr ԁο ɡеt hacked οr find webspam οn уουr site, аnԁ aren’t sure whаt tο ԁο, don’t panic аnԁ ѕtаrt deleting files. Thіѕ саn mаkе thе situation much worse.

Instead, take screengrabs οf thе issue, аnԁ send thеm tο someone whο specializes іn WordPress (οr whatever уουr blogging software іѕ) along wіth thе mοѕt recently renowned ехсеƖƖеnt backups. Thіѕ issue іѕ very common, ѕο thеrе аrе many whο specialize іn helping fix јυѕt thіѕ situation.

Of course, thеѕе аrе јυѕt vital tips fοr prevention thаt everyone ѕhουƖԁ take. Thеrе аrе more well ahead tips (fοr example, locking down thе /wp-admin/ directory wіth аn .htaccess file) bυt іf уου саn ѕtаrt out bу implementing thе tips above, уου’ll bу now bе a сυt safer thаn mοѕt.

Hаѕ уουr site bееn hacked? TеƖƖ υѕ whаt happened—аnԁ hοw уου rectified thе problem—іn thе comments.

WordPress Multisite Settings

Exclusively 2 Screenshots of the new WordPress 3.0 Multisite Settings. You can find them under Options->Network:

After you set the settings, you receive in a second step the content for wp-config.php and .htaccess. Additionally you have to create the subfolder blogs.dir in wp-content , where you put the media-files for each blog.

WordPress 3 Site Blueprints [Ebook]

  • Everything you need to build a varied collection of feature-rich customized WordPress websites for yourself.
  • Transform a static website into a dynamic WordPress blog.
  • In-depth coverage of several WordPress themes and plugins.
  • Packed with screenshots and step-by-step instructions to help you complete each site.

Sure, WordPress can be used for blogging, but this powerful software is capable of so much more. With the right combination of plugins, themes, customizations, and configurations WordPress can be transformed into a community portal, an e-commerce site, and much more. While it is easy to get started with WordPress, its full power is not obvious. There is very little that WordPress can’t do—if you can image it, then it’s probably possible with WordPress. If you want to create a powerful, fully-featured blog or non-blog website in no time, this book is for you.



WordPress Template Hierarchy

Home Page display

  1. home.php
  2. index.php

Front Page display

  1. front-page.php – Used for both Your latest posts or A static page as set in the Front page displays section of Administration > Settings > Reading
  2. Page display rules – When Front page is set in the Front page displays section of Administration > Settings > Reading
  3. Home Page display rules – When Posts page is set in the Front page displays section of Administration > Settings > Reading

Single Post display

  1. single-{post_type}.php – If the post_type were videos, WordPress would look for single-videos.php.
  2. single.php
  3. index.php

Page display

Page Templates:

  1. custom template – Where custom template is the Page Template assigned to the Page.
  2. page-{slug}.php – If the page slug is recent-news, WordPress will look to use page-recent-news.php
  3. page-{id}.php – If the page ID is 6, WordPress will look to use page-6.php
  4. page.php
  5. index.php

Category display

Category Templates:

  1. category-{slug}.php – If the category’s slug were news, WordPress would look for category-news.php
  2. category-{id}.php – If the category’s ID were 6, WordPress would look for category-6.php
  3. category.php
  4. archive.php
  5. index.php

Tag display

Tag Templates:

  1. tag-{slug}.php – If the tag’s slug were sometag, WordPress would look for tag-sometag.php
  2. tag-{id}.php – If the tag’s ID were 6, WordPress would look for tag-6.php
  3. tag.php
  4. archive.php
  5. index.php

Custom Taxonomies display

  1. taxonomy-{taxonomy}-{term}.php – If the taxonomy were sometax, and taxonomy’s slug were someterm WordPress would look for taxonomy-sometax-someterm.php
  2. taxonomy-{taxonomy}.php – If the taxonomy were sometax, WordPress would look for taxonomy-sometax.php
  3. taxonomy.php
  4. archive.php
  5. index.php

Author display

Author Templates:

  1. author-{nicename}.php – If the author’s nice name were rami, WordPress would look for author-rami.php.
  2. author-{id}.php – If the author’s ID were 6, WordPress would look for author-6.php.
  3. author.php
  4. archive.php
  5. index.php

Date display

Archive (Date) Templates:

  1. date.php
  2. archive.php
  3. index.php

Search Result display

Search Templates:

  1. search.php
  2. index.php

404 (Not Found) display

404 Templates:

  1. 404.php
  2. index.php

Attachment display

Attachment Templates:

  1. MIME_type.php – it can be any MIME type (image.php, video.php, audio.php, application.php or any other).
  2. attachment.php
  3. single.php
  4. index.php

Useful WordPress functions

I compiled a list of 15 useful WordPress Functions you probably don’t know. Some are simple and can be used by pretty much everyone; others have less common uses; but, all of them are incredibly useful.

WordPress Transient API

set_transient(), get_transient(), delete_transient()

This is a function set very similar to get_options() and update_options() which helps to easily store and retrieve data in your options database table. The big difference here is that you also pass a time parameter which acts as expiration date for the database entry.

Once the time has expired the data is removed. This is especially useful if you want to cache data or query results for a short amount of time. An example would be a twitter widget which retrieves data from the twitter api, but since twitter is down pretty often it would be wise to save that data for a few minutes. That also would speed up the site for subsqequent page requests since you don’t need to connect to an external API.

It works pretty easy: the function set_transient accepts 3 parameters:

set_transient($transient, $value, $expiration);

so saving a value to your database for an hour would look like this:

set_transient('the_name', $special_query_results, 60*60);

getting the value like this:

$value = get_transient('the_name');


WordPress “Cron Jobs”

wp_schedule_event(time(), 'hourly', 'my_schedule_hook');

Schedules a hook which will be executed by the WordPress actions core on a specific interval, specified by you. The action will trigger when someone visits your WordPress site, if the scheduled time has passed.

So if you want to execute some code on a regular base, like checking an RSS Feed, doing a database backup or reseting database values this function will do it for you. Unfortunatley its not as easy to use as transient but here is a short article on how it is done:



WordPress HTTP API

wp_remote_get( $url, $args = array() );

An easy to use function if you want to retrieve the content of a Webpage. The function stores the result within an easily accessible array. Not only do you get the result content of the webpage, you also get header informations and response codes. This function is also capable of retrieving feed content which also makes it useful if you want to create a twitter plugin or an rss reader with wordpress.



Easily Fetch an RSS Feed with WordPress

$feed = fetch_feed( $uri );

fetch_feed is another simple wordpress method to get feed content. It also has the added benefit that it uses the SimplePie and FeedCache functionality for retrieval and parsing and automatic caching.


WordPress mail function

wp_mail( $to, $subject, $message, $headers, $attachments );
$to = 'mail@mail.com';
$subject = 'Hello Egis!';
$message = 'This message was sent by wordpress'
$mail = wp_mail($to, $subject, $message);
if($mail) echo 'Mail delivered';

An incredible useful and exceptional easy to use function that also allows you to send headers and attachments, allows plain text sending and html messages and quite a few other options!


WordPress Human Time

human_time_diff( $from, $to )

A feature to mimic twitter like time display. Instead of outputting the time in a basic format you can display it like this:

Kriesi posted 13 hours ago


WordPress get comments


Sometimes its neccessary to retrieve the comments outside of the comments loop like I did with the Avia Feedback Box Plugin, where comments are displayed via ajax. This function helps you in doing so


WordPress validation of strings

wp_kses($string, $allowed_html, $allowed_protocols);

wp_kses is a very usefull function when it comes to sanitizing untrusted user input. This function makes sure that only the allowed HTML element names, attribute names and attribute values plus only sane HTML entities will occur in $string.


WordPress text transformation


A text transformation function that converts commonly used strings into the typographical correct signs. Used for dashes, ellipsis etc and will also add typograpic quotes to certain phrases.



The last text transformation tool on the list is used by wordpress to ad <p> tags to a string by replacing double <br/> tags


WordPress Shortcode API

add_shortcode(), do_shortcode()

add_shortcode() is an easy way to create macros for your post content. for example lets say you want to wrap some content inside the post area within a div with some additional classes and ids that allows you to create multiple columns. you could of course just switch to the html editor and enter

<div class='one_third'>Content goes here</div>

Easier and more convenient especially if you are dealing with customers who dont know html would be a shortcode solution within your functions.php file:

function column_shortcode( $atts, $content = null ) {
   return '<div class='one_third>' . $content . '</div>';
add_shortcode('one_third_column', 'column_shortcode');

You could then use this shortcode in your post content:

[one_third_column]Content goes here[/one_third_column]

If you would like to nest shortcodes within each other you would need to make sure to add the do_shortcode method to your function like this:

column_shortcode( $atts, $content = null ) {
   return '<div class='one_third>' . do_shortcode($content) . '</div>';


Create WordPress post with a php function:


This function inserts posts pages and custom post types in the database. It sanitizes variables, does some checks, fills in missing variables like date/time, etc. very handy when you need to create and insert posts by user input. This function fits perfectly if you have a front end form for example and users can suggest posts.


Create WordPress comment with a php function:


Similar to wp_insert_posts this function inserts a comment. Might also come in handy


WordPress Object Cache:

wp_cache_add(),  wp_cache_set(),  wp_cache_get(),  wp_cache_delete, wp_cache_replace(), wp_cache_flush

WP_Object_Cache is WordPress’ class for caching data which may be computationally expensive to regenerate, such as the result of complex database queries. If you care for theme and plugin performance you should definitley read the wordpress codex entry for this topic!


Kill wordpress execution:


An appropriate end for this post: the wp_die function

wp_die kills the WordPress execution and display HTML message with error message.

A call to this function complements the die() PHP function. The difference is that HTML will be displayed to the user. It is recommended to use this function only when the execution should not continue any further.


Web Accessibility Checklist


• Separate structure from presentation and use proper markup for that structure. For example, mark up lists as lists (<ul>, <ol>, <dl>) rather than text with a <br> tag after each list item.

• headings (e.g. <h1>) are very helpful for blind users.

HTML Properly mark up the sections of a page and body copy with headings rather than something such as a <p> tag with CSS    HTML styling that makes it look like a heading.

• Give pages meaningful and accurate titles using the <title> tag.

• Indicate the primary human language of the document using the lang  attribute in the <html> tag, and indicate any passages in a secondary language using the lang attribute on other tags wrapping the relevant text (e.g. “<span lang=”es”>Hola</span>means Hello”).

• Provide “Skip to content” links at the top of the markup order in pages with large numbers of navigational links before the main content.

• Always indicate headers in data tables using <th> tags, and  associate all data cells with their header.

• Be sure tab order is logical using tabindex, if necessary. (If your HTML is in the proper order, then using tabindex isn’t necessary.)


• Be sure your page is still usable when images are turned off. (is  may include making sure that contrast is still sufficient if you happen to be using a background image and that image is removed.)

• Be sure pages remain usable when users enlarge text up to twice its original size.

• Be sure each element on a page is reachable and can be manipulated via the keyboard.

• Whenever possible, write descriptive headings and link textswhich can be understood when read out of context (e.g. no “click here” links).

• For color-blind and low-vision users, be sure your content and  background have sufficient contrast.

• Do not use content that flashes or blinks more than three times a second.

• Do not hide the focus indicator. When a user uses the keyboard to tab from element to element, it should always be apparent where they are.

• Do not require users to perceive font, color, or other styling changes in order to understand meaning. For instance, don’t say,“e highlighted word in the previous paragraph is the most important,” or “Items marked in red are errors and need to be corrected,” unless the word or items are indicated in some other way.


Be sure all images have an alt attribute, leaving the text for decorational images blank (e.g. alt=””).

• Always add alt text when images are also links.

• In general, be brief with alt text (e.g. “Notre Dame Cathedral”),but provide detail when it conveys meaning (e.g. “Son standing at his father’s graveside with mother in arms”).

• Provide a transcript, captions, and/or sign language translation for all audio and video with speech.

• Provide a “described” version of a video when description is necessary for unsighted users to understand content. (e described audio track can either be distributed with the video  content, or as an audio only file.)

• Be sure that all videos, if they don’t autoplay, have, at the very least, an accessible Play control.

• When text can be rendered just as well by the browser as it can in an image, avoid using images for text. (Image replacement techniques are often an acceptable alternate, but also consider translation requirements when using text in or as images.)

• Avoid CAPTCHA s unless you have no other choice, and even then they should be avoided. However, if you must use them, provide an audio CAPTCHA alternative.


• Always label all form fields with the <label> tag. If a form field  has no specific text label on the page, add one, and hide it with CSS or use the title attribute.

• Use fieldsets (<fieldset>) with legends (<legend>) to associate prompts with radio buttons and check boxes. For instance, a form  asks “Gender:” and offers radio buttons that say “Male” or “Female”. en “Gender:” should be enclosed in a <legend> tag, and all three elements (<legend> and the two radio buttons with  their label text) should be enclosed in a <fieldset> tag.

• Identify all input errors in text (in addition to any images or icons), and place the error notification either next to the affected field or in a prominent location such as the top of the page with

an anchor link to the affected field.

• Provide help links or inline instructions for completing fields  when necessary.

• Do not permit users to complete important actions without a confirmation or a way to undo.

• Avoid using HTML elements in nonstandard ways (e.g. form elements for navigation, links for form submission, etc.).