WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Term search - Difference between name__like and search (4 posts)

  1. TCBarrett
    Member
    Posted 1 year ago #

    http://codex.wordpress.org/Function_Reference/get_terms

    name__like
    (string) Default is empty string.
    search
    (string) The term name you wish to match. It does a LIKE %term name% query.

    What's the difference?

  2. keesiemeijer
    moderator
    Posted 1 year ago #

    There is a subtle difference.
    This is the "name__like" query from the get_terms() function with some explanation:

    $where .= $wpdb->prepare( " AND t.name LIKE %s", $name__like . '%' );
    
    // $where varable with $name_like = hello
    // $where .= " AND t.name LIKE 'hello%'";

    And the search query:

    $where .= $wpdb->prepare( " AND (t.name LIKE %s)", '%' . $search . '%');
    
    // $where varable with with $search = hello
    // $where .= " AND (t.name LIKE '%hello%')";

    The "name__in" parameter will do a query for terms that begin with with the "name__in" string and the "search" parameter will query for any terms that contains the "search" string.

    http://en.wikipedia.org/wiki/Where_%28SQL%29#LIKE

  3. TCBarrett
    Member
    Posted 1 year ago #

    Thanks!

    I think you should put that in the codex! :)

  4. keesiemeijer
    moderator
    Posted 1 year ago #

    You're welcome.

    If you want, you can edit the codex yourself by logging in with your WordPress forum username and password:

    http://make.wordpress.org/support/handbook/contributing-to-the-wordpress-codex/
    http://codex.wordpress.org/index.php?title=Special:UserLogin&returnto=Main_Page

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.