• Hi everyone.

    Is there a way to pass multiple terms into the search parameter for the get_bookmarks function? The same way include,exclude,category pass ID numbers? I’m assuming no, but would like to make sure.

    for instance…

    $bm = get_bookmarks(array(
    ‘orderby’ => ‘rand’,
    ‘order’ => ‘desc’,
    ‘limit’ => -1,
    ‘hide_invisible’ => 1,
    ‘show_updated’ => 0,
    ‘include’ => null,
    ‘exclude’ => ”,
    ‘search’ => ‘term1, term2’
    ));

    Many thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi,

    Unfortunately as I can see from source code this function dont split “search” param by ‘,’ as it does with ‘include’ and others.
    So, there is no way.

    You can copy this function to your plugin and change this behavior ??
    Also you can make several calls and then merge results.

    Thread Starter batten1000

    (@batten1000)

    Thanks wpua.
    I have pulled in my search terms in comma delineated fashion like thus (single.php):

    $posttags = get_the_tags();
    if ($posttags) {
    foreach ($posttags as $tag) {
    $tagnames[count($tagnames)] = $tag->name;
    }
    $comma_separated_tagnames = implode(“, “, $tagnames);
    }
    $bm = get_bookmarks(array(
    ‘orderby’ => ‘rand’,
    ‘search’ => $comma_separated_tagnames
    ));

    The relevant code to in includes/bookmark.php is this:
    if ( ! empty($search) ) {
    $search = like_escape($search);
    $search = ” AND ( (link_url LIKE ‘%$search%’) OR (link_name LIKE ‘%$search%’) OR (link_description LIKE ‘%$search%’) ) “;
    }

    I’m stuck here, as I have tried to adapt some of the inc/exc logic. It doesnt work as expected. Any advice? Thanks again.

    It should be something like this:

    if ( ! empty($search) ) {
    $search_parts = array();
    foreach(explode(',', $search) as $search_item) {
      $search_item = like_escape(trim($search_item));
      $search_parts[] = "(link_url LIKE '%$search_item%') OR (link_name LIKE '%$search_item%') OR (link_description LIKE '%$search_item%')";
    }
    
    $search = " AND ( ". join(' OR ', $search_parts) ." ) ";
    }

    Thread Starter batten1000

    (@batten1000)

    Thanks wpua, you’re the best!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘pass multiple search terms to get_bookmarks’ is closed to new replies.