Pass blog title to search plug-in and display the results.

I am modifying the blog plug-in and I want to add the following functionality: When a user adds a new blog title, actions/blog/save.php file should be able to send the title of the blog to elgg search plug-in and show search results instead of the current view where the user can add a comment to the newly added blog.


I am a new developer, and would appreciate any help and tips to use the search plug-in. Before posting this question, I have looked at groups plug-in where a tag field is captured from the form, but found no such code for capturing the search result.


Thanks in advance.

  • If I understand you correctly you want the user to be redirected to the search result page (with blog title as search term) after saving a blog.

    At the end of the save action file there's the forward for published blogs (as opposed to forwards for draft blogs and in case of errors). Modify it as follows

            if ($blog->status == 'published' || $save == false) {
    //             forward($blog->getURL());
                $search_url = elgg_normalize_url("search?q={$blog->title}&search_type=all");
            } else {

    Lines in bold are modified.

  • @iionly Thank you for your reply.

    Yes, that is exactly what I want. I tried your solution but it did not work. It redirects me to:


    I can get the correct search url as follows:

    $search_url = elgg_get_site_url() . 'search';

    but do not how to properly tokenize the search string q. I can do it by additional logic but I am wondering if there is an elggish way to do it.

    Another, way to solve it could be to set search (q) field in the sidebar but that did not work either. Here is what I tried:

    $body = elgg_view_form('blog/search', array(
            'action' => $url,
            'method' => 'put',
            'disable_security' => true,
            'q' => "this is a test",

    echo elgg_view_module('aside', elgg_echo("search in topics"), $body);


  • @iionly I was able to create a working url using http_build_query to parse the query string.


    Please share If you know how to pass and get query string from the form. $field = get_input('q', $default, false); did not return the query string.

  • I don't know which version of Elgg you are currently using but I'm quite sure it's not Elgg 2.3.2 (very latest release). When testing the code I suggested yesterday it also didn't work for me at first - same problem with invalid url forwarded to. Problem was due to the spaces in the blog title (and therefore also spaces in the search query in the url) which fail to work correctly at least on Elgg 2.3.1 (maybe also on earlier Elgg version). This bug has been fixed in Elgg 2.3.2. And after updating my test installation from 2.3.1 to 2.3.2 the code I suggested worked.

    So, please update to Elgg 2.3.2 and test again.

Beginning Developers

Beginning Developers

This space is for newcomers, who wish to build a new plugin or to customize an existing one to their liking