Skip to:
Content
Pages
Categories
Search
Top
Bottom

[Resolved] Separate form from search results using shortcode


  • ibrahim_alfors
    Participant

    @ibrahim_alfors

    Hello everyone,

    I’m using some custom code to add a search functionality in my buddypress site. I’m done with the code that does the actual searching and its working well. However, I want the results of the search to be in a different section of the page from the Form, so I thought I would use two different shortcodes for the search form and for the search results, like this,

    Some Page content
    [search_form] //the text boxes and submit button
    Some Page content
    [search_results] //the resulting members

    I tried making two functions with different shortcodes in the functions.php and I added them in the page with some content between them but the content is always pushed to the bottom so the form and the results are always in the top of the page and follow each other.

    Any thoughts on what is causing this or how this is done?

Viewing 5 replies - 1 through 5 (of 5 total)

  • ibrahim_alfors
    Participant

    @ibrahim_alfors

    Could anyone help me with this matter, I know it hasn’t been long time but its kind of urgent

    Thanks everyone.


    shanebp
    Moderator

    @shanebp

    I’ll bet you’re using echo in your shortcode functions.

    So their output appears before the page content is rendered.
    Use return instead of echo.
    https://codex.wordpress.org/Shortcode_API


    ibrahim_alfors
    Participant

    @ibrahim_alfors

    Thanks for the reply,

    When I try this

    function getCustomMembersForm(){
    return '<form> .... </form>';
    }

    I get this error
    unexpected ‘<‘ in xxx\functions.php on line xx


    shanebp
    Moderator

    @shanebp

    You’re probably making a mistake with single vs double quotes.
    Try:

    function getCustomMembersForm(){
      $str = 'This will be the start of my form.<br/>';
      $str .= 'Put "something" in quotes.<br/>';
      $str .= 'And this will be the end of my form.';
      return $str;
    }

    ibrahim_alfors
    Participant

    @ibrahim_alfors

    well, this is embarrassing, rookie mistake with some string concatenations

    Thanks for the help, this saved me a lot of time.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘[Resolved] Separate form from search results using shortcode’ is closed to new replies.
Skip to toolbar